【问题标题】:Text file is busy error from a shell script file来自 shell 脚本文件的文本文件正忙错误
【发布时间】:2021-11-11 15:15:11
【问题描述】:

我目前正在做一个基于用户输入编写和执行 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 脚本时,我都会收到错误消息:文本文件正忙

【问题讨论】:

  • self.installPath 在哪里定义?和open()调用中的install.sh一样吗?如果是这样,我会在尝试执行之前关闭正在编写的脚本的文件。
  • 您标记了这个 linux,但这听起来更像是 Windows 错误消息。

标签: python linux shell


【解决方案1】:

我所要做的就是在执行之前关闭文件,如第一条评论中所述。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-14
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    相关资源
    最近更新 更多