eryksun added the comment:

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.

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16892>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to