473,320 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Command Line arguments

I have a question about Windows based python (2.4 and later).

For example, if I make a script called test.py like so:

import sys
print sys.argv

then run it:

python test.py this is a test

I see a list with

['test.py', 'this', 'is', 'a', 'test']
All is good!

BUT...

If i make .py extensions be run as exes (by setting the .py extension to
be executable with PATHEXT setting in environment variables, the Python
program will run, but NO arguments are passed!

For example, after setting .py extension to be executable, i get this:

test this is a test

I get ['test.py]. NO arguments are passed.

NOTE: This can NOT be blamed on Windows in my mind because Python2.2 and
earlier works FINE.

Any one have an idea?

Thank you!

Michael
Aug 25 '05 #1
7 2301
michael <sa*******@aol.com> wrote:
I have a question about Windows based python (2.4 and later).

For example, if I make a script called test.py like so:

import sys
print sys.argv

then run it:

python test.py this is a test

I see a list with

['test.py', 'this', 'is', 'a', 'test']
All is good!

BUT...

If i make .py extensions be run as exes (by setting the .py extension to
be executable with PATHEXT setting in environment variables, the Python
program will run, but NO arguments are passed!

For example, after setting .py extension to be executable, i get this:

test this is a test

I get ['test.py]. NO arguments are passed.

NOTE: This can NOT be blamed on Windows in my mind because Python2.2 and
earlier works FINE.


It is a configuration problem. Bring up a Command Shell and run the assoc
and ftype commands like this:

C:\Tmp>assoc .py
.py=Python.File

C:\Tmp>ftype Python.File
Python.File="C:\Apps\Python24\python.exe" "%1" %*

C:\Tmp>

The KEY part of that is the %* at the end of the Python.File defintion.
That tells the system to insert the rest of the command line parameters at
that point. If you have ONLY the "%1", the command will run but no
parameters will be forwarded. If so, you can fix this by typing:

C:\Tmp>ftype Python.File="C:\Apps\Python24\python.exe" "%1" %*

Substituting your own path, of course.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Aug 25 '05 #2
On Thu, 25 Aug 2005 00:46:41 -0700, Tim Roberts wrote:
michael <sa*******@aol.com> wrote:
I have a question about Windows based python (2.4 and later).

For example, if I make a script called test.py like so:

import sys
print sys.argv

then run it:

python test.py this is a test

I see a list with

['test.py', 'this', 'is', 'a', 'test']
All is good!

BUT...

If i make .py extensions be run as exes (by setting the .py extension to
be executable with PATHEXT setting in environment variables, the Python
program will run, but NO arguments are passed!

For example, after setting .py extension to be executable, i get this:

test this is a test

I get ['test.py]. NO arguments are passed.

NOTE: This can NOT be blamed on Windows in my mind because Python2.2 and
earlier works FINE.


It is a configuration problem. Bring up a Command Shell and run the assoc
and ftype commands like this:

C:\Tmp>assoc .py
.py=Python.File

C:\Tmp>ftype Python.File
Python.File="C:\Apps\Python24\python.exe" "%1" %*

C:\Tmp>

The KEY part of that is the %* at the end of the Python.File defintion.
That tells the system to insert the rest of the command line parameters at
that point. If you have ONLY the "%1", the command will run but no
parameters will be forwarded. If so, you can fix this by typing:

C:\Tmp>ftype Python.File="C:\Apps\Python24\python.exe" "%1" %*

Substituting your own path, of course.

Tim,

I can confirm you were right! Thank you very much.

This will get us through the issue. I wonder why this was needed? One way
or the other, you taught me something and I thank you.

Michael Christopher
Aug 25 '05 #3
On Thu, 25 Aug 2005 00:46:41 -0700, Tim Roberts wrote:
michael <sa*******@aol.com> wrote:
I have a question about Windows based python (2.4 and later).

For example, if I make a script called test.py like so:

import sys
print sys.argv

then run it:

python test.py this is a test

I see a list with

['test.py', 'this', 'is', 'a', 'test']
All is good!

BUT...

If i make .py extensions be run as exes (by setting the .py extension to
be executable with PATHEXT setting in environment variables, the Python
program will run, but NO arguments are passed!

For example, after setting .py extension to be executable, i get this:

test this is a test

I get ['test.py]. NO arguments are passed.

NOTE: This can NOT be blamed on Windows in my mind because Python2.2 and
earlier works FINE.


It is a configuration problem. Bring up a Command Shell and run the assoc
and ftype commands like this:

C:\Tmp>assoc .py
.py=Python.File

C:\Tmp>ftype Python.File
Python.File="C:\Apps\Python24\python.exe" "%1" %*

C:\Tmp>

The KEY part of that is the %* at the end of the Python.File defintion.
That tells the system to insert the rest of the command line parameters at
that point. If you have ONLY the "%1", the command will run but no
parameters will be forwarded. If so, you can fix this by typing:

C:\Tmp>ftype Python.File="C:\Apps\Python24\python.exe" "%1" %*

Substituting your own path, of course.


SOLVED! Thank you.

I wonder why this was needed for 2.4 and not 2.2? I don't think it was
lingering things from old installs because it happened on a persons
computer that had never had any python installed before 2.4.

Anyway, THANKS!

Michael

Aug 25 '05 #4
[michael wrote]
SOLVED! Thank you.

I wonder why this was needed for 2.4 and not 2.2? I don't think it was
lingering things from old installs because it happened on a persons
computer that had never had any python installed before 2.4.


It might be due to a bug in the Python 2.4 installer not setting the
proper file associations. What installer package did you use?

Trent

--
Trent Mick
Tr****@ActiveState.com
Aug 25 '05 #5
On Thu, 25 Aug 2005 11:39:48 -0700, Trent Mick wrote:
[michael wrote]
SOLVED! Thank you.

I wonder why this was needed for 2.4 and not 2.2? I don't think it was
lingering things from old installs because it happened on a persons
computer that had never had any python installed before 2.4.


It might be due to a bug in the Python 2.4 installer not setting the
proper file associations. What installer package did you use?

Trent


I used the python2.4.MSI from python.org site (dated 3-6-05). I think this
was the first time they went to MSI verses an exe based installer.

it says Python 2.4 (#60 November 30th, 2004) when I start it.

Michael

Aug 26 '05 #6
[michael wrote]
I wonder why this was needed for 2.4 and not 2.2? I don't think it was
lingering things from old installs because it happened on a persons
computer that had never had any python installed before 2.4.


[Trent] It might be due to a bug in the Python 2.4 installer not setting the
proper file associations. What installer package did you use?


I used the python2.4.MSI from python.org site (dated 3-6-05). I think this
was the first time they went to MSI verses an exe based installer.

it says Python 2.4 (#60 November 30th, 2004) when I start it.


I think Martin has been doing MSIs for a little bit longer than that,
but I'm not sure.

Martin, is it possible that there is a bug in setting up the
..py/Python.File association in the python2.4.msi? Here is the start of
this thread:

http://mail.python.org/pipermail/pyt...st/296007.html

What association (if any) does your Python MSI setup?

Cheers,
Trent

--
Trent Mick
Tr****@ActiveState.com
Aug 26 '05 #7
Trent Mick wrote:
I used the python2.4.MSI from python.org site (dated 3-6-05). I think this
was the first time they went to MSI verses an exe based installer.

it says Python 2.4 (#60 November 30th, 2004) when I start it.

I think Martin has been doing MSIs for a little bit longer than that,
but I'm not sure.


I started after 2.3, but MSIs were released for the 2.4 alpha and beta
releases, as well.
Martin, is it possible that there is a bug in setting up the
.py/Python.File association in the python2.4.msi? Here is the start of
this thread:

http://mail.python.org/pipermail/pyt...st/296007.html
I don't think the 2.4 MSI has such a bug. There were various issues
in the alpha releases, but they got resolved. There was a bug in
the shortcuts (IDLE would not start if TARGETDIR had a space in it),
but that is an unrelated issue. Please refer to

http://www.python.org/2.4/bugs.html

for the most frequently reported bugs in 2.4.
What association (if any) does your Python MSI setup?


"assoc .py" gives "Python.File", "ftype Python.File" gives
Python.File="C:\Python24\python.exe" "%1" %*

This is all done through registry (i.e. no advertised extensions).
Software\Classes\.py is Python.File,
Software\Classes\Python.File\shell\open\command is
"[TARGETDIR]python.exe" "%1" %*

My guess is that the MSI file was installed "Just for me",
and then a different user tries to find the associations,
which fails as they are in the other user's profile.

Alternatively, the "Register Extensions" feature in
the "Customize Python 2.4" dialog may have been
deselected.

Regards,
Martin
Aug 26 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hari | last post by:
can i have command line arguments in VS.NET applicatio? if yes how? Can i have some code snippets of the above functionality? I know we can acjieve this in console application form command...
6
by: Jon Hewer | last post by:
hi i am writing a little script and currently implementing command line arguments following the guide by mark pilgrim from dive into python; ...
7
by: Steve M | last post by:
I'm trying to invoke a Java command-line program from my Python program on Windows XP. I cannot get the paths in one of the arguments to work right. The instructions for the program describe the...
2
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
1
by: amirmira | last post by:
I would like to set command line arguments to a service at install time. I need to do this because I need to get information from different registry locations depending on my command line argument....
1
by: Rune Jacobsen | last post by:
Hi, I've been trying to figure this one out, but my experience just doesn't have what it takes... :| I am writing an application that reads an XML file and displays the contents in various...
4
by: Roland | last post by:
Hi, I am developing a C++ project and want to pass some command line arguments in VS .NET 2003. I am in debug mode, the configuration is set to Debug and I entered my argument list in Project ->...
40
by: raphfrk | last post by:
I have a program which reads in 3 filenames from the command line prog filename1 filename2 filename3 However, it doesn't work when one of the filenames has spaces in it (due to a directory...
2
by: Milan | last post by:
Hi, Please guide me how to set command line argument and how to retrive command line argument. Senario: vb.net application should be able to execute from command prompt by passing login and...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.