sys.argv problem in Win 2k 
Author Message
 sys.argv problem in Win 2k

Hi pythonistas

       All my python scripts on Win 2k does not take command line arguments.
i.e, len(sys.argv) is always 1. Because of this I cannot use any scripts which
takes cmd line arguments.

 Any ideas ?

Regards

Anand Pillai



Mon, 10 Oct 2005 17:21:33 GMT  
 sys.argv problem in Win 2k

Quote:

> Hi pythonistas

>        All my python scripts on Win 2k does not take command line arguments.
> i.e, len(sys.argv) is always 1. Because of this I cannot use any scripts which
> takes cmd line arguments. [...]

#v+
D:\tmp>copy con: test.py
import sys
print sys.argv
^Z
         1 file(s) copied.

D:\tmp>c:\Python22\python.exe test.py bla blubs
['test.py', 'bla', 'blubs']

D:\tmp>test.py bla blubs
['D:\\tmp\\test.py', 'bla', 'blubs']

D:\tmp>
#v-

Works fine here. Can you show exactly what does not work with a test case?

-- Gerhard



Mon, 10 Oct 2005 17:37:12 GMT  
 sys.argv problem in Win 2k
Sure...

#example+
#cmdtest.py
import sys

print sys.argv
for x in sys.argv:
    print x

D:\OpensourceApps>cmdtest.py passing arguments
['D:\\OpensourceApps\\cmdtest.py']
D:\OpensourceApps\cmdtest.py
#example-

 As you see the arguments I pass are not being printed!
This is the case with all my scripts now. They were working
well when I was on a WinNT workstation :-?

Regards

ABP

Quote:


> > Hi pythonistas

> >        All my python scripts on Win 2k does not take command line arguments.
> > i.e, len(sys.argv) is always 1. Because of this I cannot use any scripts which
> > takes cmd line arguments. [...]

> #v+
> D:\tmp>copy con: test.py
> import sys
> print sys.argv
> ^Z
>          1 file(s) copied.

> D:\tmp>c:\Python22\python.exe test.py bla blubs
> ['test.py', 'bla', 'blubs']

> D:\tmp>test.py bla blubs
> ['D:\\tmp\\test.py', 'bla', 'blubs']

> D:\tmp>
> #v-

> Works fine here. Can you show exactly what does not work with a test case?

> -- Gerhard



Mon, 10 Oct 2005 21:06:49 GMT  
 sys.argv problem in Win 2k


Quote:
>  As you see the arguments I pass are not being printed!
> This is the case with all my scripts now. They were working
> well when I was on a WinNT workstation :-?

What does the command 'assoc .py' print?
What does the command 'ftype Python.File' print?

Running a .py file depends on the file association which the assoc command
will show, and if it is Python.File the ftype command will show how the
command line is passed.

They should look something like this:

D:\temp>ftype Python.File
Python.File=D:\Python22\python.exe "%1" %*

D:\temp>assoc .py
.py=Python.File

--

int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



Mon, 10 Oct 2005 21:19:02 GMT  
 sys.argv problem in Win 2k
Hi Duncan

 There was a problem with this but I fixed it in the
registry. Now the associations are fine, but still the
cmd line problem remains!

#test+
F:\users\anand\LocalWorkspaces\ResModWS>ftype Python.File
Python.File=D:\Python22\pythonw.exe "%1"

F:\users\anand\LocalWorkspaces\ResModWS>ftype Python.File
Python.File=D:\Python22\python.exe "%1"

F:\users\anand\LocalWorkspaces\ResModWS>assoc .py
.py=Python.File

F:\users\anand\LocalWorkspaces\ResModWS>assoc .pyw
.pyw=Pythonw.File

F:\users\anand\LocalWorkspaces\ResModWS>ftype Pythonw.File
Pythonw.File=D:\Python22\pythonw.exe "%1"
#test-

#example+
#cmdtest.py
import sys

print sys.argv
for x in sys.argv:
    print x

D:\OpensourceApps>cmdtest.py
['D:\\OpensourceApps\\cmdtest.py']
D:\OpensourceApps\cmdtest.py
#example-

 Huh ?  ---

Thanks

ABP

Quote:



> >  As you see the arguments I pass are not being printed!
> > This is the case with all my scripts now. They were working
> > well when I was on a WinNT workstation :-?

> What does the command 'assoc .py' print?
> What does the command 'ftype Python.File' print?

> Running a .py file depends on the file association which the assoc command
> will show, and if it is Python.File the ftype command will show how the
> command line is passed.

> They should look something like this:

> D:\temp>ftype Python.File
> Python.File=D:\Python22\python.exe "%1" %*

> D:\temp>assoc .py
> .py=Python.File



Tue, 11 Oct 2005 15:10:58 GMT  
 sys.argv problem in Win 2k

Quote:

>> D:\temp>ftype Python.File
>> Python.File=D:\Python22\python.exe "%1" %*



Quote:
> F:\users\anand\LocalWorkspaces\ResModWS>ftype Python.File
> Python.File=D:\Python22\python.exe "%1"

Spot the difference.

The "%1" passes the name of the script to python.exe, the %* passes all the
other arguments. Without the %* windows will simply drop the other
arguments on the floor.

--

int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



Tue, 11 Oct 2005 15:47:19 GMT  
 sys.argv problem in Win 2k
Well I was hoping that would fix it!
I tried

Python.File=D:\Python22\python.exe "%1" %*
and
Python.File=D:\Python22\python.exe "%*"
and another 2 combinations,

But still I cannot pass the cmd line arguments!
Let me try and figure out myself :-O

ABP

Quote:


> >> D:\temp>ftype Python.File
> >> Python.File=D:\Python22\python.exe "%1" %*



> > F:\users\anand\LocalWorkspaces\ResModWS>ftype Python.File
> > Python.File=D:\Python22\python.exe "%1"

> Spot the difference.

> The "%1" passes the name of the script to python.exe, the %* passes all the
> other arguments. Without the %* windows will simply drop the other
> arguments on the floor.



Wed, 12 Oct 2005 19:24:02 GMT  
 sys.argv problem in Win 2k

Quote:
>Well I was hoping that would fix it!
>I tried

>Python.File=D:\Python22\python.exe "%1" %*
>and

above should work IF assoc .py => .py=Python.File

If assoc .py => .py=someOtherName
check ftype someOtherName and see if the %* is left off.

Quote:
>Python.File=D:\Python22\python.exe "%*"

above should fail to work

Quote:
>and another 2 combinations,

>But still I cannot pass the cmd line arguments!
>Let me try and figure out myself :-O

Maybe you have a different association via .py -- e.g., I don't have the dotted name:

[10:28] C:\pywk\clp>assoc .py
.py=Pythonfile

[10:28] C:\pywk\clp>ftype Pythonfile
Pythonfile=d:\python22\python.exe "%1" %*

Quote:

>ABP


>> >> D:\temp>ftype Python.File
>> >> Python.File=D:\Python22\python.exe "%1" %*



>> > F:\users\anand\LocalWorkspaces\ResModWS>ftype Python.File
>> > Python.File=D:\Python22\python.exe "%1"

>> Spot the difference.

>> The "%1" passes the name of the script to python.exe, the %* passes all the
>> other arguments. Without the %* windows will simply drop the other
>> arguments on the floor.

Regards,
Bengt Richter


Thu, 13 Oct 2005 01:27:44 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. I need help to install COBOL on my Win 2k sys

2. Chosing between sys.argv and sys.stdin

3. Win32 problems: Popen3 and sys.argv[0]

4. Win 2K app problem

5. Weird Win 2K indexing problem

6. MASM problems in Win 2k.

7. understanding sys.argv[]

8. sys module - argv, but no argc ??

9. sys.argv and while loop

10. sys.argv not found

11. catch empty sys.argv

12. sys.argv in Python 2.0 does not work?

 

 
Powered by phpBB® Forum Software