execl difficulty

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • python newbie

    execl difficulty

    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



  • Bengt Richter

    #2
    Re: execl difficulty

    On Sun, 14 Dec 2003 20:53:10 GMT, "python newbie" <mesteve_b@hotm ail.com> wrote:
    [color=blue]
    >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[/color]

    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:\W INDOWS\system32 \xcopy.exe", r"E:\MainWeb\dr eampics\*.*", 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

    Comment

    • python newbie

      #3
      Re: execl difficulty

      I tried that and it didn't work, but I like the direction you suggested.
      Thanks, I'll figure this sucker out.
      "Bengt Richter" <bokr@oz.net> wrote in message
      news:briksl$oc4 $0@216.39.172.1 22...[color=blue]
      > On Sun, 14 Dec 2003 20:53:10 GMT, "python newbie" <mesteve_b@hotm ail.com>[/color]
      wrote:[color=blue]
      >[color=green]
      > >Can anyone tell me why this would cause "Invalid Number of Parameters"[/color][/color]
      while[color=blue][color=green]
      > >trying to compile (or interpret or whatever)
      > >
      > >import os[/color]
      >
      >os.execl("C:/WINDOWS/system32/xcopy.exe","E:/MainWeb/dreampics/*.*","E:/Mai[/color]
      n[color=blue][color=green]
      > >Web/dp")
      > >
      > >Here's what the Python reference says:
      > > execl(path,arg0 , arg1, ...)
      > >
      > >if you can see something obvious, please tell me[/color]
      >
      > I think xcopy uses suffixed optional forward-slash switch options, so it[/color]
      might be getting confused?[color=blue]
      > I'd try (note the 'r' prefixes for raw string literals):
      >
      > os.execl(r"C:\W INDOWS\system32 \xcopy.exe",[/color]
      r"E:\MainWeb\dr eampics\*.*", r"E:\MainWeb\dp ")[color=blue]
      >
      > I don't know what the length or count limits might be on expansion of[/color]
      "*.*" but hopefully[color=blue]
      > it it pretty big.
      >
      > Regards,
      > Bengt Richter[/color]


      Comment

      • Fredrik Lundh

        #4
        Re: execl difficulty

        "python newbie" wrote:
        [color=blue]
        > 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, ...)[/color]

        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>




        Comment

        • Bengt Richter

          #5
          Re: execl difficulty

          On Mon, 15 Dec 2003 00:18:32 +0100, "Fredrik Lundh" <fredrik@python ware.com> wrote:
          [color=blue]
          >"python newbie" wrote:
          >[color=green]
          >> 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, ...)[/color]
          >
          >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.
          >[/color]
          Hmph, I missed that, in spite of the fact that I execl'd my C++ args printer:

          Like OP's xcopy execl:
          [color=blue][color=green][color=darkred]
          >>> os.execl(r'c:\u til\pargs.exe', '1', '2', '3')[/color][/color][/color]
          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,arg v[i]);
          }
          return 0;
          }

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

          Regards,
          Bengt Richter

          Comment

          • python newbie

            #6
            Re: execl difficulty

            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" <fredrik@python ware.com> wrote in message
            news:mailman.14 6.1071443928.93 07.python-list@python.org ...[color=blue]
            > "python newbie" wrote:
            >[color=green]
            > > Can anyone tell me why this would cause "Invalid Number of Parameters"[/color][/color]
            while[color=blue][color=green]
            > > trying to compile (or interpret or whatever)
            > >
            > > import os
            > >[/color][/color]
            os.execl("C:/WINDOWS/system32/xcopy.exe","E:/MainWeb/dreampics/*.*","E:/Main[color=blue][color=green]
            > > Web/dp")
            > >
            > > Here's what the Python reference says:
            > > execl(path,arg0 , arg1, ...)[/color]
            >
            > 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>
            >
            >
            >
            >[/color]


            Comment

            • Gerrit Holl

              #7
              Re: execl difficulty

              Fredrik Lundh wrote:[color=blue]
              > "python newbie" wrote:[color=green]
              > > 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, ...)[/color][/color]
              [color=blue]
              > (are you sure you want os.exec, btw? os.system or os.spawn* might
              > be a better choice...)[/color]

              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:


              Comment

              • J.R.

                #8
                Re: execl difficulty

                You may try
                os.execl("c:\\W INDOWS\system32 \xcopy.exe", "E:\\MainWeb\\d reampics\\*.*",
                "E:\\MainWeb\\d p")

                J.R.

                "python newbie" <mesteve_b@hotm ail.com> wrote in message
                news:W44Db.3921 3$B03.19442@new ssvr29.news.pro digy.com...[color=blue]
                > Can anyone tell me why this would cause "Invalid Number of Parameters"[/color]
                while[color=blue]
                > trying to compile (or interpret or whatever)
                >
                > import os
                >[/color]
                os.execl("C:/WINDOWS/system32/xcopy.exe","E:/MainWeb/dreampics/*.*","E:/Main[color=blue]
                > Web/dp")
                >
                > Here's what the Python reference says:
                > execl(path,arg0 , arg1, ...)
                >
                > if you can see something obvious, please tell me
                > thanks
                > Steve
                >
                >
                >[/color]


                Comment

                • Fredrik Lundh

                  #9
                  Re: execl difficulty

                  "J.R." <j.r.gao@motoro la.com> wrote:
                  [color=blue]
                  > You may try
                  > os.execl("c:\\W INDOWS\system32 \xcopy.exe", "E:\\MainWeb\\d reampics\\*.*",
                  > "E:\\MainWeb\\d p")[/color]

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

                  ValueError: invalid \x escape

                  </F>




                  Comment

                  • J.R.

                    #10
                    Re: execl difficulty

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

                    os.execl("c:\\W INDOWS\\system3 2\\xcopy.exe",
                    "E:\\MainWeb\\d reampics\\*.*", "E:\\MainWeb\\d p")

                    J.R.

                    "Fredrik Lundh" <fredrik@python ware.com> wrote in message
                    news:mailman.18 7.1071569341.93 07.python-list@python.org ...[color=blue]
                    > "J.R." <j.r.gao@motoro la.com> wrote:
                    >[color=green]
                    > > You may try
                    > > os.execl("c:\\W INDOWS\system32 \xcopy.exe",[/color][/color]
                    "E:\\MainWeb\\d reampics\\*.*",[color=blue][color=green]
                    > > "E:\\MainWeb\\d p")[/color]
                    >
                    > that's a rather verbose way to get a compilation error:
                    >
                    > ValueError: invalid \x escape
                    >
                    > </F>
                    >
                    >
                    >
                    >[/color]


                    Comment

                    Working...