Python Forum
using subpocess for both reading and writing simultaneously
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
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.

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

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020