Text file is busy error from a shell script file

Issue

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('yes\n'.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

Solution

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

Answered By – Teer 2008

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published