0

I am trying to create a background running file, and I want the file to open a file, wait for its termination and activate some code after. I want to open the file in the path /../foo.exe. Any help appreciated.

I tried process = subprocess.Popen([f"start {os.path.dirname(__file__)}foo.exe"]) But I got the error message:

Traceback (most recent call last):
  File "C:\Users\ORI\Desktop\everything\General stuff\EasyRP-windows\configs\background.py", line 5, in <module>
    process = subprocess.Popen([f"start {os.path.dirname(__file__)}foo.exe"]) #\\..\\easyrp.exe"
  File "C:\Users\ORI\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\ORI\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
no jif
  • 3
  • 4
  • Is the file being closed by your script, or by some other program? – John Gordon Jan 05 '21 at 16:38
  • I tried doing `process = subprocess.Popen([f"start {os.path.dirname(__file__)}foo.exe"])' but i got an error message. @JohnGordon – no jif Jan 05 '21 at 16:39
  • @JohnGordon the file is being closed manually, by pressing the x button of the program. – no jif Jan 05 '21 at 16:39
  • 2
    If you got an error message from the popen command, show it to us. Telling us "I got an error message" isn't very helpful. – John Gordon Jan 05 '21 at 16:40
  • @JohnGordon Sorry, edited the post to have the error. – no jif Jan 05 '21 at 16:42
  • It may be better to say that you want to execute a program and wait for its termination. – tdelaney Jan 05 '21 at 16:43
  • 1
    @nojif according to that error, you're just specifying the file path incorrectly. – Random Davis Jan 05 '21 at 16:44
  • 1
    you need an extra slash `os.path.join(os.path.dirname(__file__)}, "foo.exe"` – tdelaney Jan 05 '21 at 16:44
  • You're telling popen to run a command that is literally named `start foo.exe`, which of course doesn't exist. You need to pass a list of each separate argument: `Popen(["start", "foo.exe"])` – John Gordon Jan 05 '21 at 16:48
  • @JohnGordon tried it, still getting the same error. I moved that the file I'm trying to access is in the same folder too, with no success. – no jif Jan 05 '21 at 16:50

0 Answers0