python - 我在使用 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
解决方案
你应该给出确切的 HelloWorld.c 路径
cmd = "/home/user/../HelloWorld.c"
推荐阅读
- qt - 在 qml 中显示大文本
- android-studio - appcompat-v7:28.0.0-beta01 更新后损坏
- javascript - 选择框和复选框在ajax中不起作用
- spring - 使 Spring 的 @RequestBody 注释在失败时返回自定义响应
- android - 通过程序操作除 main_xml 之外的 xml
- selenium - 等待执行两个动作 - selenium/java
- python - 找不到请求的 Boost 库
- vim - 如何在 Vim 中更改运算符突出显示颜色?
- certificate - 创建知道数字签名密钥的.key文件
- python - 在 OpenCV 中跳过帧并寻找到 RTSP 流的结尾