开发者

how run gcc command from python script

开发者 https://www.devze.com 2022-12-07 22:10 出处:网络
I\'m using this command from the terminal to create开发者_JAVA百科 a text file that saves the errors without creating an output file.

I'm using this command from the terminal to create开发者_JAVA百科 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 +++
0

精彩评论

暂无评论...
验证码 换一张
取 消