Skip to content
Advertisement

Text file is busy error from a shell script file

I am currently working on a project that writes and executes a shell script based on the input of the user.

           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()

And I run the Shell file with this:

    def installSoftware(self):
        self.shellscript = subprocess.Popen([self.installPath], shell=True, stdin=subprocess.PIPE )
        self.shellscript.stdin.write('yesn'.encode("utf-8"))
        self.shellscript.stdin.close()
        self.returncode = self.shellscript.wait()

But whenever the code executes the shell script, I get the error message: Text file is busy

Advertisement

Answer

All I had to do is close the file before executing it as described in the first comment.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement