I’m using Windows Vista and Python 2.7.2, but answers needn’t be in Python.
So I can start and interact with a subprocesses stdin/stdout normally (using python), for command-line programs such as `dir’.
– however –
the program I now want to call likes to make a new console window for itself on Windows (not curses), with new handles, even when run from a pre-existing cmd.exe window. (Odd, as it’s the “remote control” interface of VLC.) Is there any way of either:
- getting the handles for the process-made console’s stdin/out; or
- getting the new shell to run within the old (like invoking bash from within bash)?
Failing that, so that I can hack the subprocesses’ code, how would a new console be set up in Windows and in/output transferred?
Edit:
I.e.
>>> p = Popen(args=['vlc','-I','rc'],stdin=PIPE,stdout=PIPE)
# [New console appears with text, asking for commands]
>>> p.stdin.write("quit\r\n")
Traceback:
File "<stdin>", line 1, in <module>
IOError: [Errno 22] Invalid argument
>>> p.stdout.readline()
''
>>> p.stdout.readline()
''
# [...]
But the new console window that comes up doesn’t accept keyboard input either.
Whereas normally:
>>> p = Popen(args=['cmd'],stdin=PIPE,stdout=PIPE)
>>> p.stdin.write("dir\r\n")
>>> p.stdin.flush()
>>> p.stdout.readline() #Don't just do this IRL, may block.
'Microsoft Windows [Version...
I haven’t gotten the rc interface to work with a piped stdin/stdout on Windows; I get
IOErrorat all attempts tocommunicateor write directly tostdin. There’s an option--rc-fake-ttythat lets the rc interface be scripted on Linux, but it’s not available in Windows — at least not in my somewhat dated version of VLC (1.1.4). Using the socket interface, on the other hand, seems to work fine.The structure assigned to the
startupinfooption — and used by the Win32CreateProcessfunction — can be configured to hide a process window. However, for the VLC rc console, I think it’s simpler to use the existing--rc-quietoption. In general, here’s how to configurestartupinfoto hide a process window:Just to be complete — in case using pipes is failing on your system too — here’s a little demo I cooked up using the
--rc-hostoption to communicate using a socket. It also uses--rc-quietto hide the console. This just prints the help and quits. I haven’t tested anything else. I checked that it works in Python versions 2.7.2 and 3.2.2. (I know you didn’t ask for this, but maybe it will be useful to you nonetheless.)