How execute a .py in this way?

P

Peter Cai

If it's a executable file, a ".exe" file, you can launch it in this
way, "xxx.exe < input.txt". The text file "input.txt" will be
considered as the standard input.

But when I use this trick on python, it doesn't work. The only way to
do so is like this "python xxx.py < input.txt". But this method has a
problem, that you have to include the full path of "xxx.py" unless
it's in your current folder even if "xxx.py" is in a folder which has
been include in the eviorment variable "path" on windows. Thus, you
can execute you "py" program anywhere by using the command "xxx.py",
but when you want to use an exsiting file as it's input, you have to
use something like "pythong xxx.py < input.txt".

It's very inconvenient as I tried to make my python programs cowork with vim.

Sorry for my poor english!
delete
 
P

Peter Hansen

Peter said:
Thus, you
can execute you "py" program anywhere by using the command "xxx.py",
but when you want to use an exsiting file as it's input, you have to
use something like "pythong xxx.py < input.txt".

This is apparently a bug or limitation of Windows command prompts and
may not be fixed any time soon. Past threads have discussed it and a
recent one even gave pointers to some web pages that explain it further.

-Peter
 
D

Dennis Lee Bieber

If it's a executable file, a ".exe" file, you can launch it in this
way, "xxx.exe < input.txt". The text file "input.txt" will be
considered as the standard input.
Since you specify a .exe file, I'm presuming you are running on
Windows...

But, the question then becomes, WHICH variation of Windows? It
would have helped to include a cut&paste of the problem you are having
as your post is unclear as to whether it is the path search for an
executable, or the redirection, that is giving you difficulty.

Some versions (W9x) don't recognize .py as a valid extension for
an exectable program, you basically have to type "python xxx" for
anything.

WinXP not only recognizes .py as a program, but will run if you
don't mention it (file is cp.py, command line is just cp)

However, I find that there is some OS set-up problem in parsing
the command line. Using "Python cp.py <xxxx" results in a redirected
stdin to the program. Using just "cp.py <xxxx" results in the OS parsing
out the redirect (which can be seen by having the program print the
arguments it sees) but that redirection not properly making it into the
program.

E:\UserData\Dennis Lee Bieber\My Documents>cp < t.rx
['E:\\UserData\\Dennis Lee Bieber\\My Documents\\cp.py']
Traceback (most recent call last):
File "E:\UserData\Dennis Lee Bieber\My Documents\cp.py", line 5, in ?
dta = sys.stdin.readlines()
IOError: [Errno 9] Bad file descriptor

As can be seen, cp.py /did/ run when invoked as just cp -- but
the < t.rx was stripped and handled by the OS, which did something that
is not liked by sys.stdin.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top