Send alt key to subprocess.PIPE stdin

Wanderer wanderer at dialup4less.com
Wed Sep 11 16:15:48 EDT 2013


On Wednesday, September 11, 2013 1:43:09 PM UTC-4, Gary Herron wrote:
> On 09/11/2013 07:26 AM, Wanderer wrote:
> 
> > How do I send the command 'Alt+D' to subprocess.PIPE?
> 
> >
> 
> > My code is
> 
> >
> 
> > import subprocess
> 
> > rsconfig = subprocess.Popen(["C:\Program Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ],stdin=subprocess.PIPE)
> 
> >
> 
> > rsconfig.stdin.write('Alt+D')
> 
> >
> 
> > Thanks
> 
> 
> 
> That question doesn't really make sense.  A pipe provides a method to 
> 
> transfer a stream of bytes.  You could indeed send that byte across the 
> 
> pipe, but it's just a byte, written by one process and read by another 
> 
> process.  The receiving process can examine the byte stream, and do 
> 
> whatever it wants in response.
> 
> 
> 
> By calling it a _command_, you seem to expect some particular behavior 
> 
> out of the receiving process.  Please tell us *what* that might be, and 
> 
> we'll see what we can do to help out.
> 
> 
> 
> Gary Herron
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Dr. Gary Herron
> 
> Department of Computer Science
> 
> DigiPen Institute of Technology
> 
> (425) 895-4418

I found Sendkeys works.

import subprocess
import time
import SendKeys

rsconfig = subprocess.Popen(["C:\Program Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ])
time.sleep(2)
SendKeys.SendKeys('%D\n', with_newlines=True)

Basically there is a dialog with a Done button and 'Alt D' selects the Done button. The subprocess program runs some interface code which sets up an ini file that the rest of the program needs. But then I run into another problem with Windows permissions. The program needs to edit this ini file located in the C:\Windows directory. Windows won't let you without administrator permissions. So then I run into login issues, etc. I kind of gave up and this program has to be run outside my main program. It's annoying since it's just this stupid little text ini file, but I can't convince Windows it doesn't matter if gets edited because it's in a system directory.



More information about the Python-list mailing list