CMD command redirection (pipes) in shortcut/link on Windows 7?

I'd like to run a Python 3 script silently on system start using a shortcut/link (.lnk) in Autostart.

Python's pythonw.exe will run as windowless process with my script only if piping stdout and stderr somewhere, e.g. pythonw script.pyw >nul 2>&1. This does work from CMD.

It does not work when given as Windows link target. This auto-expands to c:\Python34\pythonw.exe script.pyw >nul 2>&1. Double qoutation marks around the command are removed automatically. The pythonw.exe process only runs briefly when running the link.


I got it to work with

C:\Windows\system32\CMD.exe /C start /B pythonw.exe script.pyw >nul 2>&1

When run, the CMD window is shown briefly. It seems the CMD pipe operators are not interpreted by the Windows link "mechanism" but rather sent to the program as arguments/options. This is resolved by actually running CMD with /C to pass the START command to run pythonw as separate process.

Further reading:

  • http://ss64.com/nt/cmd.html - Start a new CMD shell and (optionally) run a command/executable program.
  • http://ss64.com/nt/start.html - Start a program, command or batch script (opens in a new window.)
  • http://ss64.com/nt/syntax-redirection.html