我想从脚本中的'tsc'获取输出。我可以使用子流程吗?
此刻,我使用os.system('tsc> errors.txt')。然后,我解析该文件。 我想在没有多余文件的情况下执行此操作,然后将输出从“ tsc”输出到我的变量。
import subprocess
subprocess.check_output(['tsc'])
并输出:
Traceback (most recent call last):
File "tsc-igonre.py", line 8, in <module>
subprocess.check_output(['tsc'])
File "C:\Program Files\Python36\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Program Files\Python36\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Program Files\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Program Files\Python36\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Cannot find the file specified