在ubuntu上的python3中运行subaccess(bash脚本)



我的结果只是空的循环日志。

如果我把手册放在终端这行命令:

python3 -m PyInstaller --onefile --name SOCIAL_NETWORK_TEST --distpath packages/projectTest --workpath .cache/ app.py

那么pack工作正常。

任何建议。

bashCommand = "python3 -m PyInstaller --onefile --name " + self.engineConfig.currentProjectName + " --distpath " + "projects/" + self.engineConfig.currentProjectName + "/Package/" + " --workpath .cache/ main.py"
print("PACK DONE,")
# no expirience
import subprocess
process = subprocess.Popen(bashCommand.split(), stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
# self.myLogs = []
for line in iter(process.stdout.readline, b'n'):
#     self.testLog = str(line)
#     self.LOGS.text = self.testLog
print ("PACKAGE:",  str(line))
print("Package application for linux ended.")

试试这个:

output = subprocess.run(["your_scritp.sh", "param1", "param2"], capture_output=True, text=True)
print(output.stdout)

要查看返回的内容,应该是一个输出字符串,若多行

您可以在命令输出行后立即使用iter处理行:lines=iter(fd.readline,"(

from __future__ import print_function # Only Python 2.x
import subprocess
def execute(cmd):
popen = subprocess.Popen(cmd, 
stdout=subprocess.PIPE, universal_newlines=True)
for stdout_line in iter(popen.stdout.readline, ""):
yield stdout_line 
popen.stdout.close()
return_code = popen.wait()
if return_code:
raise  subprocess.CalledProcessError(return_code,cmd)
bashCommand = "python3 -m PyInstaller --onefile --name " + self.engineConfig.currentProjectName + " --distpath " + "projects/" + self.engineConfig.currentProjectName + "/Package/" + " --workpath .cache/ main.py"
print("PACK DONE,")
execute(bashCommand) 

相关内容

  • 没有找到相关文章

最新更新