首页 > 解决方案 > 我在使用 subprocess 命令时遇到错误

问题描述

这是python代码

import subprocess

cmd = "HelloWorld.c"
# Example
# cmd = HelloWorld.c
print("Hey this is Python Script Running\n")
subprocess.call(["gcc", cmd])  # For Compiling
subprocess.call("./a.out", shell = True)

# end thats all

这是C代码

#include<stdio.h>

 int main()
 {
     printf("Hello World\n");
     printf("This C program Running\n");
     return 0;
 }

这是错误代码。

嘿,这是正在运行的 Python 脚本

Traceback (most recent call last):
  File "C:/Users/Yogi/PycharmProjects/Last_Subprocess_Try/Subprocess/Test.py", line 7, in <module>
    subprocess.call(["gcc", cmd])  # For Compiling
FileNotFoundError: [WinError 2] The system cannot find the file specified
Process finished with exit code 1

标签: pythonpython-3.xsubprocess

解决方案


你应该给出确切的 HelloWorld.c 路径

cmd = "/home/user/../HelloWorld.c"

推荐阅读