This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients BreamoreBoy, eryksun, oeffner, steve.dower, tim.golden, zach.ware
Date 2014-07-17.15:42:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1405611728.27.0.443213406497.issue16892@psf.upfronthosting.co.za>
In-reply-to
Content
Doskey is a command-line interface for a subset of the Win32 console API. Macros are implemented as console input aliases by calling AddConsoleAlias. 

http://msdn.microsoft.com/en-us/library/ms681935

You can load macros from a text file that defines aliases for multiple EXEs:

    doskey /macrofile=doskey.cfg

Create this file from your current macros: 

    doskey /macros:all > doskey.cfg

You can also use ctypes to add an alias. 

    #!python3
    import ctypes
    import subprocess
    
    AddConsoleAliasW = ctypes.windll.kernel32.AddConsoleAliasW
    AddConsoleAliasW.argtypes = [ctypes.c_wchar_p] * 3
    
    # $db => import builtins;dir(builtins)
    AddConsoleAliasW("$db",
                     "import builtins;dir(builtins)",
                     "python.exe")

    #subprocess.call("doskey")
    subprocess.call("stdintest.exe", shell=True)

The "bug" occurs if I uncomment the line to run doskey. 

When stdin is a file, calling sys.stdin.tell() before and after running doskey shows that it's reading standard input, for whatever reason. That's its prerogative, not a bug. Calling sys.stdin.seek(0) after running doskey works, but that's not a possibility when doskey is run via the cmd shell's AutoRun.

By the way, redirection to a file is not a pipe. It actually works for a pipe such as

    type mytxtfile.txt | testsubproc.py

The good news is that you only need to load doskey macros once for a given console window. You can use an AutoRun script that tests and sets an environment variable:

    @echo off
    if "%AUTORUN_DOSKEY%"=="No" goto end
    echo %0: setting doskey macros
    "%SystemRoot%\System32\doskey.exe" /macrofile="%AppData%\doskey.cfg"
    set AUTORUN_DOSKEY=No

    :end

This should take care of cases where you're redirecting standard input to a file, assuming the shell wasn't started with the /d option to skip AutoRun. 

On Posix systems /bin/sh -c doesn't execute .profile, .bashrc, etc. So maybe on Windows Popen should use %ComSpec% /d /c. You'd still have this problem with os.system, however.
History
Date User Action Args
2014-07-17 15:42:08eryksunsetrecipients: + eryksun, tim.golden, BreamoreBoy, zach.ware, steve.dower, oeffner
2014-07-17 15:42:08eryksunsetmessageid: <1405611728.27.0.443213406497.issue16892@psf.upfronthosting.co.za>
2014-07-17 15:42:08eryksunlinkissue16892 messages
2014-07-17 15:42:07eryksuncreate