Python Forum
Subprocess command prompt (Windows)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subprocess command prompt (Windows)
#6
I changed it a bit adding flush() but I still can't figure it to work.
This is the code:
from subprocess import *

p = Popen(['cmd', '/k', 'Command that does something and asks for a password'], stdin=PIPE)
p.stdin.write(b'test\r\n' *2)
p.stdin.flush()
I also removed the shell=True because it's not recommended in the python subprocess docs. If you remove it you need to add 'cmd', '/k' to make it work. The /k will open the terminal and run the command or you can run /c to just run it without opening a terminal.

It still asks me for password and to verify it so it's not working yet.
Reply


Messages In This Thread
Subprocess command prompt (Windows) - by arnaur - Sep-03-2018, 08:51 AM
RE: Subprocess command prompt (Windows) - by arnaur - Sep-03-2018, 09:43 AM
RE: Subprocess command prompt (Windows) - by arnaur - Sep-03-2018, 10:58 AM
RE: Subprocess command prompt (Windows) - by arnaur - Sep-04-2018, 10:34 AM
RE: Subprocess command prompt (Windows) - by arnaur - Sep-06-2018, 07:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  'pip' not recogmnized in windows prompt MaartenRo 1 449 Dec-21-2023, 09:05 AM
Last Post: menator01
  What is the difference between Command Prompt and Sublimes yaoyao22 1 673 Jul-09-2023, 02:56 PM
Last Post: snippsat
  Using subprocess to execute complex command with many arguments medatib531 5 1,966 Apr-27-2023, 02:23 PM
Last Post: medatib531
  [SOLVED] [Windows] Right way to prompt for directory? Winfried 4 2,116 Jan-17-2023, 09:28 PM
Last Post: markoberk
  Open windows cmd prompt and run cmds with python Extra 3 1,501 Jul-14-2022, 06:07 AM
Last Post: Gribouillis
  Facing Problem while opening a file through command prompt vlearner 4 1,975 Jan-30-2022, 08:10 AM
Last Post: snippsat
  use subprocess on linux\pi wwith a "grep " command korenron 2 8,227 Oct-19-2021, 10:52 AM
Last Post: DeaD_EyE
  disable subprocess.popen prompt echo paul18fr 1 2,052 Feb-04-2021, 02:50 AM
Last Post: Larz60+
  Noob warning: trying to use pip to install pytest and pep8 in Command Prompt adifrank 4 5,419 Dec-20-2020, 04:23 AM
Last Post: adifrank
  Running Python in Command Prompt Anwar 3 3,139 Nov-15-2020, 03:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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