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
#11
(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.
Reply


Messages In This Thread
RE: using subpocess for both reading and writing simultaneously - by volcano63 - May-30-2018, 08:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fastest Way of Writing/Reading Data JamesA 1 2,314 Jul-27-2021, 03:52 PM
Last Post: Larz60+
  Writing list as a file, then reading that file as a list Zoastria_Balnala 3 2,745 Oct-17-2019, 07:54 PM
Last Post: Zoastria_Balnala
  How to run same process simultaneously exploit123 1 2,529 Sep-19-2019, 10:08 AM
Last Post: Gribouillis
  Reading and writing files JakeHoward4 1 1,911 Aug-07-2019, 06:22 PM
Last Post: Yoriz
  Problem with reading and writing to file. darktitan 2 2,405 Jul-20-2019, 06:06 PM
Last Post: darktitan
  Control 2 stepper motor simultaneously jihene 2 4,179 May-08-2019, 05:27 PM
Last Post: DeaD_EyE
  Moving with objects simultaneously kom2 1 3,153 Apr-20-2019, 07:12 PM
Last Post: SheeppOSU
  reading csv and writing csv chawas 2 2,990 Aug-23-2018, 09:28 AM
Last Post: chawas
  controlling multiple server simultaneously. caligola 3 3,741 May-11-2018, 05:44 PM
Last Post: wavic
  How to define two functions run simultaneously within a function? Alberto 4 4,212 Feb-06-2018, 10:08 PM
Last Post: Alberto

Forum Jump:

User Panel Messages

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