Python 3.x 在ubuntu上的python3中运行SubAccess(bash脚本)

Python 3.x 在ubuntu上的python3中运行SubAccess(bash脚本),python-3.x,ubuntu,Python 3.x,Ubuntu,我的结果只是空的循环日志 如果我将手动输入终端,则该行命令: python3 -m PyInstaller --onefile --name SOCIAL_NETWORK_TEST --distpath packages/projectTest --workpath .cache/ app.py 那么包装就可以了 任何建议 bashCommand = "python3 -m PyInstaller --onefile --name " + self.engi

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

如果我将手动输入终端,则该行命令:

python3 -m PyInstaller --onefile --name SOCIAL_NETWORK_TEST --distpath packages/projectTest --workpath .cache/ app.py
那么包装就可以了

任何建议

        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,“”)


您是否尝试在调试器中单步执行代码?没有任何消息,没有错误,只有空的日志循环…我可以使用简单字符串(bashCommand)“作为您的\u scritp.sh”吗?我现在看到“没有这样的文件或目录:”必须是shell!现在我需要根据我的字符串在磁盘上写shell文件。。。我将尝试您的案例,我建议:output=subprocess.run([“python3”、“-m”、“PyInstaller”、“-onefile”、……直到最后]。。。
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)