By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,398 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,398 IT Pros & Developers. It's quick & easy.

execl difficulty

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On Sun, 14 Dec 2003 20:53:10 GMT, "python newbie" <me*******@hotmail.com> wrote:
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
Jul 18 '05 #2

P: n/a
I tried that and it didn't work, but I like the direction you suggested.
Thanks, I'll figure this sucker out.
"Bengt Richter" <bo**@oz.net> wrote in message
news:br**********@216.39.172.122...
On Sun, 14 Dec 2003 20:53:10 GMT, "python newbie" <me*******@hotmail.com> wrote:
Can anyone tell me why this would cause "Invalid Number of Parameters" whiletrying to compile (or interpret or whatever)

import os
os.execl("C:/WINDOWS/system32/xcopy.exe","E:/MainWeb/dreampics/*.*","E:/Mai

n
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

Jul 18 '05 #3

P: n/a
"python newbie" wrote:
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>


Jul 18 '05 #4

P: n/a
On Mon, 15 Dec 2003 00:18:32 +0100, "Fredrik Lundh" <fr*****@pythonware.com> wrote:
"python newbie" wrote:
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:
os.execl(r'c:\util\pargs.exe', '1', '2', '3')

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[i]);
}
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
Jul 18 '05 #5

P: n/a
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" <fr*****@pythonware.com> wrote in message
news:ma*************************************@pytho n.org...
"python newbie" wrote:
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>

Jul 18 '05 #6

P: n/a
Fredrik Lundh wrote:
"python newbie" wrote:
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, ...)
(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
--
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/

Jul 18 '05 #7

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

J.R.

"python newbie" <me*******@hotmail.com> wrote in message
news:W4*******************@newssvr29.news.prodigy. com...
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

Jul 18 '05 #8

P: n/a
"J.R." <j.*****@motorola.com> wrote:
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>


Jul 18 '05 #9

P: n/a
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.

"Fredrik Lundh" <fr*****@pythonware.com> wrote in message
news:ma*************************************@pytho n.org...
"J.R." <j.*****@motorola.com> wrote:
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>

Jul 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.