0

I have written some short DOSKEYS that I've got in a .bat file. I have one that let's me run a python program from any directory as long as i know the python file's directory and I have one that lets me run my python file if I know the directory of my python installation. They are "runpy" and "cmdprogram" respectively. I can call runpy and give my python file's directory but cmdprogram doesn't work.

runpy:

DOSKEY runpy = C:\Python34\python $*

cmdprogram:

DOSKEY cmdprogram = C:\Users\ivar\cmd_programs\helloworld.py

Does anyone know what I'm doing wrong? Thanks for any help!

------Bonus------

The final idea is to be able to call "runpy cmdprogram helloworld.py" where cmdprogram has been altered to the following:

DOSKEY cmdprogram = C:\Users\ivar\cmd_programs\ $*

So this points me to the directory where I will be storing all my scripts and then I give the name of the file I want to use. Any ideas to get this to work are also greatly appreciated.

Ivar Eriksson
  • 863
  • 1
  • 15
  • 30
  • doskey.exe is just a program to set input aliases for the current console window by calling [`AddConsoleAlias`](https://msdn.microsoft.com/en-us/library/ms681935). Console aliases match at the *beginning* of a line of input and modify the input that gets read by the console application (e.g. cmd.exe, powershell.exe, python.exe, etc). So what you want to do cannot be done with a console alias. – Eryk Sun Nov 14 '15 at 13:19
  • Note also that your `runpy` alias won't work as a general command; you can't pipe to it since it only matches at beginning of a line of input. It also won't work in a batch file because it exists in the console (i.e. conhost.exe) and is only applied when reading input from the console, not from a file. – Eryk Sun Nov 14 '15 at 13:21
  • You have Python 3.4 installed, so .py files should be associated with py.exe. Just put all of your scripts in a single directory that you add to the `PATH` environment variable. Then run the script directly as `helloworld.py`. py.exe will take care of finding python.exe, and you can have it look for a particular Python version by adding a shebang line to the script. If you add `.PY` to the `PATHEXT` environment variable, then you can simplify it further to just `helloworld` without the .py extension. – Eryk Sun Nov 14 '15 at 13:27

0 Answers0