我目前正在从事一个项目,该项目根据用户的输入编写并执行shell脚本。
if self.ShellInput == "install":
if self.enterdPassword == True:
self.instPack = input(str("Package Name: "))
self.fullInstall = "echo " + self.userPassword + " | sudo -S apt -y install " + self.instPack
with open('install.sh', 'w') as self.installShell:
self.installShell.write(self.fullInstall)
print("SOFTWARE IS NOW READY")
ShellScriptHandeler.OpenShellscript.installSoftware()
我用下面的代码运行Shell文件:
def installSoftware(self):
self.shellscript = subprocess.Popen([self.installPath], shell=True, stdin=subprocess.PIPE )
self.shellscript.stdin.write('yes\n'.encode("utf-8"))
self.shellscript.stdin.close()
self.returncode = self.shellscript.wait()
但是,每当代码执行shell脚本时,我都会收到错误消息:文本文件繁忙
发布于 2021-09-16 09:22:18
我所要做的就是按照第一个注释中的描述,在执行文件之前关闭它。
https://stackoverflow.com/questions/69211628
复制