execl difficulty

Discussion in 'Python' started by python newbie, Dec 14, 2003.

  1. 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
     
    python newbie, Dec 14, 2003
    #1
    1. Advertising

  2. On Sun, 14 Dec 2003 20:53:10 GMT, "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, ...)
    >
    >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
     
    Bengt Richter, Dec 14, 2003
    #2
    1. Advertising

  3. I tried that and it didn't work, but I like the direction you suggested.
    Thanks, I'll figure this sucker out.
    "Bengt Richter" <> wrote in message
    news:briksl$oc4$0@216.39.172.122...
    > On Sun, 14 Dec 2003 20:53:10 GMT, "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:/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
     
    python newbie, Dec 14, 2003
    #3
  4. "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>
     
    Fredrik Lundh, Dec 14, 2003
    #4
  5. On Mon, 15 Dec 2003 00:18:32 +0100, "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, ...)

    >
    >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);
    }
    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
     
    Bengt Richter, Dec 15, 2003
    #5
  6. 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" <> wrote in message
    news:...
    > "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>
    >
    >
    >
    >
     
    python newbie, Dec 15, 2003
    #6
  7. python newbie

    J.R. Guest

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

    J.R.

    "python newbie" <> wrote in message
    news:W44Db.39213$...
    > 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
    >
    >
    >
     
    J.R., Dec 15, 2003
    #7
  8. python newbie

    Gerrit Holl Guest

    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/
     
    Gerrit Holl, Dec 15, 2003
    #8
  9. "J.R." <> 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>
     
    Fredrik Lundh, Dec 16, 2003
    #9
  10. python newbie

    J.R. Guest

    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" <> wrote in message
    news:...
    > "J.R." <> 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>
    >
    >
    >
    >
     
    J.R., Dec 17, 2003
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PC

    pipe() dup2() fork() execl() select()

    PC, Aug 9, 2003, in forum: C Programming
    Replies:
    3
    Views:
    1,323
  2. Chris Green

    Popen3-style os.execl?

    Chris Green, May 18, 2004, in forum: Python
    Replies:
    4
    Views:
    359
    Michael Hudson
    May 19, 2004
  3. Erik Johnson

    execl() and inheritied streams

    Erik Johnson, Sep 28, 2004, in forum: Python
    Replies:
    2
    Views:
    413
    Erik Johnson
    Sep 28, 2004
  4. shalombi

    Execl() in windows

    shalombi, Sep 23, 2005, in forum: C Programming
    Replies:
    1
    Views:
    741
    Keith Thompson
    Sep 24, 2005
  5. kisshug

    execl function

    kisshug, Dec 25, 2005, in forum: C Programming
    Replies:
    1
    Views:
    438
    Jack Klein
    Dec 25, 2005
Loading...

Share This Page