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
#1
Hello
I have a very simple python code cpt.py:
for i in xrange(2):
   print i                 # line 2
   ans = raw_input()       # line 3
   print ans               # line 4
I want to write another python program that run cpt.py,
read the first item (printed by line 2) echo that value
which will be read by line 3, read the new line (line 4)
an do it twice since cpt.py loop 2 times.

I tried without success (since I am asking !)
cmd = "cpt.py"
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE)
p.stdout.readline(ans) # read the print i (line 2)
p.stdin.writelines(ans)# write it (line3)
p.stdout.readline(ans) # read the print a (line 3)
p.stdout.readline(ans) # read  (line 2) second time
p.stdin.writelines(ans)# write it(line 3) second time
p.stdout.readline(ans) # read (ligne 3) second time
Thank you very much

JC
Reply


Messages In This Thread
using subpocess for both reading and writing simultaneously - by dauriac - May-29-2018, 02:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fastest Way of Writing/Reading Data JamesA 1 2,187 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,591 Oct-17-2019, 07:54 PM
Last Post: Zoastria_Balnala
  How to run same process simultaneously exploit123 1 2,441 Sep-19-2019, 10:08 AM
Last Post: Gribouillis
  Reading and writing files JakeHoward4 1 1,810 Aug-07-2019, 06:22 PM
Last Post: Yoriz
  Problem with reading and writing to file. darktitan 2 2,285 Jul-20-2019, 06:06 PM
Last Post: darktitan
  Control 2 stepper motor simultaneously jihene 2 4,015 May-08-2019, 05:27 PM
Last Post: DeaD_EyE
  Moving with objects simultaneously kom2 1 3,015 Apr-20-2019, 07:12 PM
Last Post: SheeppOSU
  reading csv and writing csv chawas 2 2,863 Aug-23-2018, 09:28 AM
Last Post: chawas
  controlling multiple server simultaneously. caligola 3 3,601 May-11-2018, 05:44 PM
Last Post: wavic
  How to define two functions run simultaneously within a function? Alberto 4 4,027 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