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

cmd.exelinksredirectionshortcutswindows

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.

Best Answer

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:

Related Question