Bottom Page

Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 using subpocess for both reading and writing simultaneously
(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 ./
In [4]: subprocess.Popen(['']) --------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) <ipython-input-4-294e3396b106> in <module>() ----> 1 subprocess.Popen(['']) /usr/lib/python3.6/ 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/ 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: '': '' In [5]: subprocess.Popen(['./']) 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.
I am so used to use the './' that I do not even notice I was using it...

In unix-like systems the current directory is never in the search path except if you add it to your environment with PATH="${PATH}:." (please, never, ever do this) so you need to add the './' to the script name.
In windows the default behaviour was like having the PATH=".:${PATH}" declared so local versions of program and dll have priority over the system ones. I do not have now any windows machine to test if subprocess.Popen also follows this rule or not.
I guess that Popen just let the OS to look for the executable and in Windows it shall work without the './' in the command, but in any case this is something to check for scripts that shall work in different SO.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Writing list as a file, then reading that file as a list Zoastria_Balnala 3 273 Oct-17-2019, 07:54 PM
Last Post: Zoastria_Balnala
  How to run same process simultaneously exploit123 1 204 Sep-19-2019, 10:08 AM
Last Post: Gribouillis
  Reading and writing files JakeHoward4 1 298 Aug-07-2019, 06:22 PM
Last Post: Yoriz
  Problem with reading and writing to file. darktitan 2 307 Jul-20-2019, 06:06 PM
Last Post: darktitan
  Control 2 stepper motor simultaneously jihene 2 513 May-08-2019, 05:27 PM
Last Post: DeaD_EyE
  Moving with objects simultaneously kom2 1 359 Apr-20-2019, 07:12 PM
Last Post: SheeppOSU
  reading csv and writing csv chawas 2 641 Aug-23-2018, 09:28 AM
Last Post: chawas
  controlling multiple server simultaneously. caligola 3 860 May-11-2018, 05:44 PM
Last Post: wavic
  How to define two functions run simultaneously within a function? Alberto 4 1,214 Feb-06-2018, 10:08 PM
Last Post: Alberto
  Reading and writing to text file has format change cheerful 3 1,108 Dec-21-2017, 07:53 AM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)