execl difficulty

P

python newbie

Can anyone tell me why this would cause "Invalid Number of Parameters" while
trying to compile (or interpret or whatever)

import os
os.execl("C:/WINDOWS/system32/xcopy.exe","E:/MainWeb/dreampics/*.*","E:/Main
Web/dp")

Here's what the Python reference says:
execl(path,arg0, arg1, ...)

if you can see something obvious, please tell me
thanks
Steve
 
B

Bengt Richter

Can anyone tell me why this would cause "Invalid Number of Parameters" while
trying to compile (or interpret or whatever)

import os
os.execl("C:/WINDOWS/system32/xcopy.exe","E:/MainWeb/dreampics/*.*","E:/Main
Web/dp")

Here's what the Python reference says:
execl(path,arg0, arg1, ...)

if you can see something obvious, please tell me

I think xcopy uses suffixed optional forward-slash switch options, so it might be getting confused?
I'd try (note the 'r' prefixes for raw string literals):

os.execl(r"C:\WINDOWS\system32\xcopy.exe", r"E:\MainWeb\dreampics\*.*", r"E:\MainWeb\dp")

I don't know what the length or count limits might be on expansion of "*.*" but hopefully
it it pretty big.

Regards,
Bengt Richter
 
P

python newbie

I tried that and it didn't work, but I like the direction you suggested.
Thanks, I'll figure this sucker out.
Bengt Richter said:
n

I think xcopy uses suffixed optional forward-slash switch options, so it might be getting confused?
I'd try (note the 'r' prefixes for raw string literals):

os.execl(r"C:\WINDOWS\system32\xcopy.exe",
r"E:\MainWeb\dreampics\*.*", r"E:\MainWeb\dp")
 
F

Fredrik Lundh

python newbie said:
Can anyone tell me why this would cause "Invalid Number of Parameters" while
trying to compile (or interpret or whatever)

import os
os.execl("C:/WINDOWS/system32/xcopy.exe","E:/MainWeb/dreampics/*.*","E:/Main
Web/dp")

Here's what the Python reference says:
execl(path,arg0, arg1, ...)

first, fix the slashes. xcopy wants backward slashes in the filenames,
not forward slashes.

next, fix the number of arguments. at the top of the reference page
you refer to, there's a paragraph explaining how the exec arguments
work:

The various exec*() functions take a list of arguments for the
new program loaded into the process. In each case, the first
of these arguments is passed to the new program as its own
name rather than as an argument a user may have typed on
a command line. For the C programmer, this is the argv[0]
passed to a program's main(). For example, "os.execv('/bin/echo',
['foo', 'bar'])" will only print "bar" on standard output;
"foo" will seem to be ignored.

(from http://www.python.org/doc/current/lib/os-process.html )

in other words, you need to pass in the program name twice, to make
sure xcopy sees the filenames as argument 1 and 2.

(are you sure you want os.exec, btw? os.system or os.spawn* might
be a better choice...)

</F>
 
B

Bengt Richter

python newbie said:
Can anyone tell me why this would cause "Invalid Number of Parameters" while
trying to compile (or interpret or whatever)

import os
os.execl("C:/WINDOWS/system32/xcopy.exe","E:/MainWeb/dreampics/*.*","E:/Main
Web/dp")

Here's what the Python reference says:
execl(path,arg0, arg1, ...)

first, fix the slashes. xcopy wants backward slashes in the filenames,
not forward slashes.

next, fix the number of arguments. at the top of the reference page
you refer to, there's a paragraph explaining how the exec arguments
work:

The various exec*() functions take a list of arguments for the
new program loaded into the process. In each case, the first
of these arguments is passed to the new program as its own
name rather than as an argument a user may have typed on
a command line. For the C programmer, this is the argv[0]
passed to a program's main(). For example, "os.execv('/bin/echo',
['foo', 'bar'])" will only print "bar" on standard output;
"foo" will seem to be ignored.

(from http://www.python.org/doc/current/lib/os-process.html )

in other words, you need to pass in the program name twice, to make
sure xcopy sees the filenames as argument 1 and 2.
Hmph, I missed that, in spite of the fact that I execl'd my C++ args printer:

Like OP's xcopy execl:
argc = 3
argv[0] = "1"
argv[1] = "2"
argv[2] = "3"

from command line, arg[0] gets inserted:

[16:35] C:\pywk\clp>c:\util\pargs.exe 1 2 3
argc = 4
argv[0] = "c:\util\pargs.exe"
argv[1] = "1"
argv[2] = "2"
argv[3] = "3"

where

[16:58] E:\VCWK\test\t3>type pargs.cpp
#include <stdio.h>
int main(const int argc,const char *argv[]){
printf("argc = %2d\n",argc);
for(int i=0;i<argc;i++){
printf("argv[%d] = \"%s\"\n",i,argv);
}
return 0;
}

Too hurried. Anyway, the above illustrates what you point out.
(are you sure you want os.exec, btw? os.system or os.spawn* might
be a better choice...)
Seems like.

Regards,
Bengt Richter
 
P

python newbie

Since you both agree, I'll try spawn. thanks for the help and the insight.
As Paul Harvey would say, good day ( or evening)
Fredrik Lundh said:
python newbie said:
Can anyone tell me why this would cause "Invalid Number of Parameters" while
trying to compile (or interpret or whatever)

import os
os.execl("C:/WINDOWS/system32/xcopy.exe","E:/MainWeb/dreampics/*.*","E:/Main
Web/dp")

Here's what the Python reference says:
execl(path,arg0, arg1, ...)

first, fix the slashes. xcopy wants backward slashes in the filenames,
not forward slashes.

next, fix the number of arguments. at the top of the reference page
you refer to, there's a paragraph explaining how the exec arguments
work:

The various exec*() functions take a list of arguments for the
new program loaded into the process. In each case, the first
of these arguments is passed to the new program as its own
name rather than as an argument a user may have typed on
a command line. For the C programmer, this is the argv[0]
passed to a program's main(). For example, "os.execv('/bin/echo',
['foo', 'bar'])" will only print "bar" on standard output;
"foo" will seem to be ignored.

(from http://www.python.org/doc/current/lib/os-process.html )

in other words, you need to pass in the program name twice, to make
sure xcopy sees the filenames as argument 1 and 2.

(are you sure you want os.exec, btw? os.system or os.spawn* might
be a better choice...)

</F>
 
J

J.R.

You may try
os.execl("c:\\WINDOWS\system32\xcopy.exe", "E:\\MainWeb\\dreampics\\*.*",
"E:\\MainWeb\\dp")

J.R.
 
G

Gerrit Holl

(are you sure you want os.exec, btw? os.system or os.spawn* might
be a better choice...)

Or shutil.copytree?

Gerrit.

--
166. If a man take wives for his son, but take no wife for his minor
son, and if then he die: if the sons divide the estate, they shall set
aside besides his portion the money for the "purchase price" for the minor
brother who had taken no wife as yet, and secure a wife for him.
-- 1780 BC, Hammurabi, Code of Law
 
F

Fredrik Lundh

J.R. said:
You may try
os.execl("c:\\WINDOWS\system32\xcopy.exe", "E:\\MainWeb\\dreampics\\*.*",
"E:\\MainWeb\\dp")

that's a rather verbose way to get a compilation error:

ValueError: invalid \x escape

</F>
 
J

J.R.

Sorry for the typo. The path delimiter on windows should be double
backslash, the
first one is for escape.

os.execl("c:\\WINDOWS\\system32\\xcopy.exe",
"E:\\MainWeb\\dreampics\\*.*","E:\\MainWeb\\dp")

J.R.
 

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

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top