简体   繁体   English

在 Python 中使用 os.system 运行程序

[英]Running a program using os.system in Python

I am trying to run Test.py using os.system(path) where I specify the path of the file but I am getting an error.我正在尝试使用os.system(path)运行Test.py ,我在其中指定了文件的路径,但出现错误。 Basically, I want to run Test.py from here and display the output.基本上,我想从这里运行Test.py并显示 output。

import os

os.system(rf"C:\\Users\\USER\\OneDrive-Technion\\Research_Technion\\Python_PNM\\Sept15_2022\\220\\1\\Test.py")

The error is错误是

The system cannot find the path specified.

you are passing a python file, not an executable.您传递的是 python 文件,而不是可执行文件。 You can pass python yourfile.py .您可以通过python yourfile.py

By the way, I would reconsider what you are doing, executing a python script from another python script is quite strange.顺便说一句,我会重新考虑你在做什么,从另一个 python 脚本执行 python 脚本是很奇怪的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM