May-30-2018, 08:58 PM
(May-30-2018, 08:43 PM)killerrex Wrote: I try not to use the shell=True mode... some bad experiences with the shell expansions.I was just explaining why it could not work - not urging to use it
(May-30-2018, 08:43 PM)killerrex Wrote: But for a python script that is in the same folder works in both ways as long as you set it executable.
OK, I set it executable and added shebang line - still need to add path - even if it is just ./
Output:In [4]: subprocess.Popen(['cpt.py'])
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-4-294e3396b106> in <module>()
----> 1 subprocess.Popen(['cpt.py'])
/usr/lib/python3.6/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
707 c2pread, c2pwrite,
708 errread, errwrite,
--> 709 restore_signals, start_new_session)
710 except:
711 # Cleanup if the child failed starting.
/usr/lib/python3.6/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1342 if errno_num == errno.ENOENT:
1343 err_msg += ': ' + repr(err_filename)
-> 1344 raise child_exception_type(errno_num, err_msg, err_filename)
1345 raise child_exception_type(err_msg)
1346
FileNotFoundError: [Errno 2] No such file or directory: 'cpt.py': 'cpt.py'
In [5]: subprocess.Popen(['./cpt.py'])
Out[5]: <subprocess.Popen at 0x7fcc683ccdd8>
As you can see, without specifying path to the script, it is still not found - not by subprocess.Popen
but rather by the opened sub-shell
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.