0

I'm using this command from the terminal to create a text file that saves the errors without creating an output file.

 strace -e write -f gcc -I/home/user/my_test/headers -fsyntax-only test_file.c 2>log.txt

I was wondering if there is a python library that allow me to run the command above using a script. I'll appreciate any suggestion. thanks.

so I tried and it works as in the terminal

import subprocess
subprocess.run(["strace", "-e", "write", "-f", "gcc", "-I/home/user/my_test/headers", "-fsyntax-only", "test_file.c"])

but if I use this

import subprocess
subprocess.run(["strace", "-e", "write", "-f", "gcc", "-I/home/user/my_test/headers", "-fsyntax-only", "test_file.c", "2>log.txt"])

it errors out. I think i'm missing something there.

write(2, "\33[01m\33[Kgcc:\33[m\33[K \33[01;31m\33[Ker"..., 81gcc: error: 2> log.txt: No such file or directory                           ) = 81                                                                
+++ exited with 1 +++
pekoms
  • 55
  • 6
  • The ‘subprocess’ module should do it. Here’s a good article/tutorial that should give you all you need: https://realpython.com/python-subprocess/ – Jacob Grumley Dec 07 '22 at 01:24
  • 1
    Is this what you're looking for? [How do I execute a program or call a system command?](/q/89228/4518341) – wjandrea Dec 07 '22 at 01:31
  • @wjandrea yeah, it works with import os cmd = 'strace -e write -f gcc -I/home/user/my_test/headers -fsyntax-only test_file.c 2>log.txt' os.system(cmd) but not with subcall. I guess that solves my problem. – pekoms Dec 07 '22 at 02:01

0 Answers0