Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to answer subprocess prompt
#1
When I run: python3.5 script.py
Which has:
process = Popen(['command args more args'], stdin=PIPE, stdout=PIPE, shell=True)
The command will prompt me to respond in Y or N with enter continue from a previous session.
This is something that I would respond Y enter
But I am unable to figure out how to respond to it
I have tried
yes = str("Y")
ayes = bytes(yes, 'utf-8')
process.communicate(ayes) #didn't bring even the Y into the console prompt

I've tried
process.communicate('Y\n') #TypeError: memoryview: a bytes-like object is required, not 'str'

and quite a lot of combinations, but I can't seem to get it to work. The machine is running linux with python3.5

I have no idea how to resolve it, even if I type Y manually into the console then it would say: "bash: y: command not found"
Quote
#2
Which command do you run in subprocess? Usually, the programmes asking you y/n have an option -y. You can just add it to the parameters when you call it.
Skaperen likes this post
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#3
reaver

The prompt only appears second after I have run the command so I am unable to answer 'y' with the beginning argument
Quote
#4
Post the command, please! What it asks for?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#5
(Feb-11-2018, 09:49 PM)Monty Wrote: I've tried
process.communicate('Y\n') #TypeError: memoryview: a bytes-like object is required, not 'str'


A bytes-like object can be created by putting a b in front of your string. Have you tried: process.communicate(b'Y\n')?
It's dangerous to go alone!  Take this: https://docs.python.org/3/library/index.html

Currently #4 in both post count, and rep. wavic and buran, I'm coming for you...
Quote
#6
(Feb-13-2018, 05:18 PM)wavic Wrote: Post the command, please! What it asks for?

process = Popen(['reaver -i wlan1mon -b my:ap:ma:ca:dr:es'], stdin=PIPE, stdout=PIPE, shell=True)
after this is run the console prompts: "Restore previous session for my:ap:ma:ca:dr:es? [n/Y]


(Feb-13-2018, 05:37 PM)nilamo Wrote:
(Feb-11-2018, 09:49 PM)Monty Wrote: I've tried
process.communicate('Y\n') #TypeError: memoryview: a bytes-like object is required, not 'str'


A bytes-like object can be created by putting a b in front of your string. Have you tried: process.communicate(b'Y\n')?

I did try process.communicate(b'Y\n')
But it doesn't run it. I'm guessing it gets stuck on that line when it prompts to continue, if that is the case then the subprocess line would never get completed. Perhaps I need another script to answer to this prompt?

Perhaps I could work-around this by creating a bash script to run a python file with only that line in the background and in the next line it would communicate to that stuck line. Seems like a stupid idea though, there must be a better way.
Quote
#7
Well, -a flag was removed from the program arguments. There is a discussion to add -y flag but appears that that isn't done yet. One option is to use -s /usr/local/etc/reaver/<BSSID>.wpc option where <BSSID>.wpc is the session file.

https://github.com/shift/reaver-wps/issues/234

By the way, see this: https://stackoverflow.com/questions/1635...n-argument
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#8
(Feb-13-2018, 06:29 PM)wavic Wrote: Well, -a flag was removed from the program arguments. There is a discussion to add -y flag but appears that that isn't done yet. One option is to use -s /usr/local/etc/reaver/<BSSID>.wpc option where <BSSID>.wpc is the session file.

https://github.com/shift/reaver-wps/issues/234

By the way, see this: https://stackoverflow.com/questions/1635...n-argument

Thank you sir. That worked.

I'm still curious on how I could run processes simultaneously and make them communicate.
Quote
#9
Probably socket interprocess communication: https://docs.python.org/3/library/ipc.html

Or by pyzmq.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Non-resizable command prompt SlimeBOOS 1 61 Jul-07-2018, 02:21 PM
Last Post: gontajones
  command prompt execution saisankalpj 5 75 Jul-05-2018, 04:31 PM
Last Post: buran
  subprocess.Popen for lively data reading? Skaperen 4 69 Jul-04-2018, 01:20 AM
Last Post: Skaperen
  Subprocess.send_signal, wait until completion plinio 5 133 Jun-29-2018, 12:07 PM
Last Post: plinio
  [inconsistent output] subprocess.call to run cmd commands to get Kerberos ticket Yelin 2 115 Jun-08-2018, 09:02 AM
Last Post: Yelin
  need help in Anaconda Prompt VirtualMan 2 131 Jun-01-2018, 04:49 PM
Last Post: snippsat
  Using Subprocess.Popen to start another python script running in background on Window johnb546 0 277 Jun-01-2018, 01:57 PM
Last Post: johnb546
  subprocess.Popen bruno 10 329 May-09-2018, 08:18 AM
Last Post: volcano63
  Typing into CMD Prompt while its behind another window andy410 0 98 Apr-27-2018, 08:24 PM
Last Post: andy410
  could you please help how to run this file on command prompt m123 6 335 Mar-24-2018, 06:55 PM
Last Post: m123

Forum Jump:


Users browsing this thread: 1 Guest(s)