Your command is missing "sh", you have to pass "shell=True" and "yes\n" has to be encoded.
Your sample code should look like this:
import subprocess
shellscript = subprocess.Popen(["sh displaySoftware.sh"], shell=True, stdin=subprocess.PIPE )
shellscript.stdin.write('yes\n'.encode("utf-8"))
shellscript.stdin.close()
returncode = shellscript.wait()
This method might be better:
import subprocess
shellscript = subprocess.Popen(["displaySoftware.sh"], shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
returncode = shellscript.communicate(input='yes\n'.encode())[0]
print(returncode)
When running this on my machine the "displaySoftware.sh" script, that is in the same directory as the python script, is successfully executed.
.shfile. Maybe the "current path" where you're running the script is not the same as the path where the script is.displaySoftware.shhas executable permissions and starts with a valid shebang, you can just change["displaySoftware.sh"]to["./displaySoftware.sh"], adding a leading./, and that's all you need to do -- noshell=True, nosh. And it works better that way, because it honors your script's shebang to select the interpreter to use../to refer to the__file__attribute of your module to find the directory with your Python source code -- that way your script will still work if it's run from a different directory than the one with the source (which is a bug you still have with the accepted answer).