0

I work on few scripts I use in Stream. I did some and now I try to do a launcher that centralize all my Scripts.

I think I'm on a good way with subprocess, but I have some difficulties atm.

I try to launch a script with this line :

subprocess.Popen(['python', "E:/path/rocksmith/rocksmith.pyw"], shell=True)

But python give me a No such file or directory error. In my script I want to launch (rocksmith.pyw) I open some text file with open() and I guess python can't find .txt file because the .txt isn't in the launcher directory right ?

My directory is like that :

Launcher folder
 - launcher.py
   * Script 1 folder
     - Script1.py
     - text.txt
   * Script 2 folder
     - Script2.py
     - text.txt
   * Script 3 folder
     - Script3.py
     - image.gif

I don't know if my explanation are ok or not. I juste want to launch some script, in a "super script".

Thanks.

1 Answers1

0

If the error is occurring when rocksmith.pyw tries to open a file, you might want to use the cwd kwarg to Popen. This will change the working directory from where the script is run, so that relative paths in rocksmith.pyw will resolve as you expect.

subprocess.Popen(['python', "E:/path/rocksmith/rocksmith.pyw"], cwd='/path/to/rocksmith/stuff')
MoxieBall
  • 1,907
  • 7
  • 23
  • 1
    On UNIX, `shell=True` is actively harmful in this use case -- `python` alone would be parsed as a shell script, and the additional argument would be ignored because the script that's given in the first argument never looks at its subsequent arguments (doesn't refer to `$0`, `$1`, etc). Might not make a difference on Windows, though; command-line handling is... different there. – Charles Duffy Jun 27 '18 at 17:48