Send alt key to subprocess.PIPE stdin

W

Wanderer

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
 
G

Gary Herron

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
 
W

Wanderer

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 Donebutton. 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.
 
D

Dave Angel

How do I send the command 'Alt+D' to subprocess.PIPE?

That's not a command, it's a keystroke combination. And without knowing
what RSConfig.exe is looking to get its keystrokes, it might not even be
possible to feed it any keystrokes via the pipe.

if the program does indeed use stdin, there's no portable encoding for
Alt-D. But if your program only runs on one particular platform, you
might be able to find docs for that platform that explain it.
My code is

import subprocess
rsconfig = subprocess.Popen(["C:\Program Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ],stdin=subprocess.PIPE)

That string will only work by accident. You need to make it a raw
string, or use forward slashes, or double them. As it happens, with
this PARTICULAR set of directories, you won't get into trouble with
Python 2.7.3
 
W

Wanderer

How do I send the command 'Alt+D' to subprocess.PIPE?



That's not a command, it's a keystroke combination. And without knowing

what RSConfig.exe is looking to get its keystrokes, it might not even be

possible to feed it any keystrokes via the pipe.



if the program does indeed use stdin, there's no portable encoding for

Alt-D. But if your program only runs on one particular platform, you

might be able to find docs for that platform that explain it.


My code is

import subprocess
rsconfig = subprocess.Popen(["C:\Program Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ],stdin=subprocess.PIPE)



That string will only work by accident. You need to make it a raw

string, or use forward slashes, or double them. As it happens, with

this PARTICULAR set of directories, you won't get into trouble with

Python 2.7.3

Thanks, I didn't know that. I thought there would be some \n \t kind of combination or a unicode string for all the key combinations on my keyboard.
 
C

Chris Angelico

Thanks, I didn't know that. I thought there would be some \n \t kind of combination or a unicode string for all the key combinations on my keyboard.

Unicode identifies every character, but keystrokes aren't characters.
Consider, for instance, the difference between the keypress Shift+A
and the letter produced - even in the most simple ASCII-only US-only
situation, that could produce either "A" or (if Caps Lock is active)
"a". So if you actually want to trigger Shift+A, you can't represent
that with a character. Controlling a GUI app has to be done with
keystrokes, so it needs a GUI controlling tool.

That said, though: These sorts of keystrokes often can be represented
with escape sequences (I just tried it in xterm and Alt-D came out as
"\e[d"), so you could control a console program using sequences that
you could put into a string. But that's not true of your typical GUI
system.

ChrisA
 
N

Nobody

That said, though: These sorts of keystrokes often can be represented
with escape sequences (I just tried it in xterm and Alt-D came out as
"\e[d"),

Technically, that would be Meta-D (even if your Meta key has "Alt" printed
on it).

Alt-<char> produces chr(ord(char)+128); Meta-<char> produces "\e"+char.

At least, that's the historical distinction between Meta and Alt. With
xterm, the behaviour is configurable via the resources altIsNotMeta,
altSendsEscape and metaSendsEscape.

None of which has anything to do with trying to feed a GUI program key
events via stdin ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top