Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6802025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:10:22+00:00 2026-05-26T19:10:22+00:00

I’m using Windows Vista and Python 2.7.2, but answers needn’t be in Python. So

  • 0

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:

  1. getting the handles for the process-made console’s stdin/out; or
  2. 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...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:10:22+00:00Added an answer on May 26, 2026 at 7:10 pm

    I haven’t gotten the rc interface to work with a piped stdin/stdout on Windows; I get IOError at all attempts to communicate or write directly to stdin. There’s an option --rc-fake-tty that 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 startupinfo option — and used by the Win32 CreateProcess function — can be configured to hide a process window. However, for the VLC rc console, I think it’s simpler to use the existing --rc-quiet option. In general, here’s how to configure startupinfo to hide a process window:

    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    subprocess.Popen(cmd, startupinfo=startupinfo)
    

    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-host option to communicate using a socket. It also uses --rc-quiet to 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.)

    import socket
    import subprocess
    from select import select
    
    try:
        import winreg
    except ImportError:
        import _winreg as winreg
    
    def _get_vlc_path():
        views = [(winreg.HKEY_CURRENT_USER, 0),
                 (winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_64KEY),
                 (winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_32KEY)]
        subkey = r'Software\VideoLAN\VLC'
        access = winreg.KEY_QUERY_VALUE
        for hroot, flag in views:
            try:
                with winreg.OpenKey(hroot, subkey, 0, access | flag) as hkey:
                    value, type_id = winreg.QueryValueEx(hkey, None)
                    if type_id == winreg.REG_SZ:
                        return value
            except WindowsError:
                pass
        raise SystemExit("Error: VLC not found.")
    
    g_vlc_path = _get_vlc_path()
    
    def send_command(sock, cmd, get_result=False):
        try:
            cmd = (cmd + '\n').encode('ascii')
        except AttributeError:
            cmd += b'\n'
        sent = total = sock.send(cmd)
        while total < len(cmd):
            sent = sock.send(cmd[total:])
            if sent == 0:
                raise socket.error('Socket connection broken.')
            total += sent
        if get_result:
            return receive_result(sock)
    
    def receive_result(sock):
        data = bytearray()
        sock.setblocking(0)
        while select([sock], [], [], 1.0)[0]:
            chunk = sock.recv(1024)
            if chunk == b'': 
                raise socket.error('Socket connection broken.')
            data.extend(chunk)
        sock.setblocking(1)
        return data.decode('utf-8')
    
    def main(address, port):
        import time
        rc_host = '{0}:{1}'.format(address, port)
        vlc = subprocess.Popen([g_vlc_path, '-I', 'rc', '--rc-host', rc_host, 
                                '--rc-quiet'])
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.connect((address, port))
            help_msg = send_command(sock, 'help', True)
            print(help_msg)
            send_command(sock, 'quit')
        except socket.error as e:
            exit("Error: " + e.args[0])
        finally:
            sock.close()
            time.sleep(0.5)
            if vlc.poll() is None:
                vlc.terminate()
    
    if __name__ == '__main__':
        main('localhost', 12345)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Specifically, suppose I start with the string string =hello \'i am \' me And
I want to construct a data frame in an Rcpp function, but when I
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.