Passing arguments to exe

Discussion in 'Python' started by kyosohma@gmail.com, Dec 14, 2007.

  1. Guest

    I have created what amounts to a simple GUI email sending program
    using Python + wxPython. I have modified the mailto registration in
    the Windows Registry so that it launches the script when someone
    clicks on someone's email link in a web page.

    While this works great if I create a convoluted path command as the
    registry entry and pass in the email argument to the script, it
    doesn't work at all if I turn my python file into an exe using py2exe.

    How does one get a python file to accept arguments when said script
    has been turned into an executable?

    I'm sure I'm just missing something obvious. I am using Python 2.4 on
    Window XP SP2.

    Thanks,

    Mike
    , Dec 14, 2007
    #1
    1. Advertising

  2. John Machin Guest

    On Dec 15, 9:01 am, wrote:
    > I have created what amounts to a simple GUI email sending program
    > using Python + wxPython. I have modified the mailto registration in
    > the Windows Registry so that it launches the script when someone
    > clicks on someone's email link in a web page.
    >
    > While this works great if I create a convoluted path command as the
    > registry entry and pass in the email argument to the script,


    It would help if you would give an actual code example of what you
    mean by "convoluted path command" and "pass in the email argument to
    the script".

    > it
    > doesn't work at all if I turn my python file into an exe using py2exe.


    "it doesn't work" is user-speak. What does it do? Does it execute the
    executable at all? If not, check your "convoluted path". If so, what
    arguments are received?

    >
    > How does one get a python file to accept arguments when said script
    > has been turned into an executable?


    If the script is expecting its arguments in sys.argv, I would expect
    that to work with an executable also. My guess is that you are falling
    foul of some argument-quoting problem. I also guess that you have not
    tried something like the following at the start of your script:

    print >> your_log_file, "sys.argv:", repr(sys.argv)

    and run it both as a script and an executable.

    Have you tried running the executable stand-alone e.g. Start | Run,
    type in
    your_exe_file
    or whatever the argument(s) are?

    HTH,
    John
    John Machin, Dec 14, 2007
    #2
    1. Advertising

  3. Guest

    On Dec 14, 4:51 pm, John Machin <> wrote:
    > On Dec 15, 9:01 am, wrote:
    >
    > > I have created what amounts to a simple GUI email sending program
    > > using Python + wxPython. I have modified the mailto registration in
    > > the Windows Registry so that it launches the script when someone
    > > clicks on someone's email link in a web page.

    >
    > > While this works great if I create a convoluted path command as the
    > > registry entry and pass in the email argument to the script,

    >
    > It would help if you would give an actual code example of what you
    > mean by "convoluted path command" and "pass in the email argument to
    > the script".


    Ok, I modify HKEY_CLASSES_ROOT\mailto\shell\open\command to do this:

    cmd /C "SET PYTHONHOME=\\servername\NETLOGON\Python24&&\\servername
    \netlogon\python24\python.exe \\path\to\my\script\wxsendmail.py %1"


    >
    > > it
    > > doesn't work at all if I turn my python file into an exe using py2exe.

    >
    > "it doesn't work" is user-speak.


    I've written posts where I've been quite technical and gotten very
    little to no response...admittedly, this was pretty vague though...


    > What does it do? Does it execute the
    > executable at all? If not, check your "convoluted path". If so, what
    > arguments are received?
    >


    The executable runs, but no argument appears to get passed into it. Of
    course, I don't really know that for sure as the executable doesn't
    redirect stdout/stderr. I tried doing something like this in the above
    reg entry:

    cmd /C "c:\program files\myProg.exe %1"
    "c:\program files\myProg.exe %1"
    "c:\program files\myProg.exe"

    None of those worked.

    >
    >
    > > How does one get a python file to accept arguments when said script
    > > has been turned into an executable?

    >
    > If the script is expecting its arguments in sys.argv, I would expect
    > that to work with an executable also. My guess is that you are falling
    > foul of some argument-quoting problem. I also guess that you have not
    > tried something like the following at the start of your script:
    >
    > print >> your_log_file, "sys.argv:", repr(sys.argv)
    >
    > and run it both as a script and an executable.



    I do have my script set up to find its arguments in sys.argv. And no,
    I don't have that print screen. As mentioned above, I don't have a
    console window open when the exe runs, so I won't see any output from
    it. I'll have to modify it to do that when I'm back at my work PC.

    >
    > Have you tried running the executable stand-alone e.g. Start | Run,
    > type in
    > your_exe_file
    > or whatever the argument(s) are?


    No, but that's a good idea. Why didn't I think of that!? (don't answer
    that)

    >
    > HTH,
    > John


    Thanks for the suggestions.

    Mike
    , Dec 15, 2007
    #3
  4. John Machin Guest

    On Dec 15, 11:38 am, wrote:
    > On Dec 14, 4:51 pm, John Machin <> wrote:
    >
    > > On Dec 15, 9:01 am, wrote:

    >
    > > > I have created what amounts to a simple GUI email sending program
    > > > using Python + wxPython. I have modified the mailto registration in
    > > > the Windows Registry so that it launches the script when someone
    > > > clicks on someone's email link in a web page.

    >
    > > > While this works great if I create a convoluted path command as the
    > > > registry entry and pass in the email argument to the script,

    >
    > > It would help if you would give an actual code example of what you
    > > mean by "convoluted path command" and "pass in the email argument to
    > > the script".

    >
    > Ok, I modify HKEY_CLASSES_ROOT\mailto\shell\open\command to do this:
    >
    > cmd /C "SET PYTHONHOME=\\servername\NETLOGON\Python24&&\\servername
    > \netlogon\python24\python.exe \\path\to\my\script\wxsendmail.py %1"
    >
    >
    >
    > > > it
    > > > doesn't work at all if I turn my python file into an exe using py2exe.

    >
    > > "it doesn't work" is user-speak.

    >
    > I've written posts where I've been quite technical and gotten very
    > little to no response...admittedly, this was pretty vague though...
    >
    > > What does it do? Does it execute the
    > > executable at all? If not, check your "convoluted path". If so, what
    > > arguments are received?

    >
    > The executable runs,


    how do you know it runs?

    > but no argument appears to get passed into it.


    appears??

    > Of
    > course, I don't really know that for sure as the executable doesn't
    > redirect stdout/stderr. I tried doing something like this in the above
    > reg entry:
    >
    > cmd /C "c:\program files\myProg.exe %1"
    > "c:\program files\myProg.exe %1"
    > "c:\program files\myProg.exe"
    >
    > None of those worked.
    >
    >
    >
    > > > How does one get a python file to accept arguments when said script
    > > > has been turned into an executable?

    >
    > > If the script is expecting its arguments in sys.argv, I would expect
    > > that to work with an executable also. My guess is that you are falling
    > > foul of some argument-quoting problem. I also guess that you have not
    > > tried something like the following at the start of your script:

    >
    > > print >> your_log_file, "sys.argv:", repr(sys.argv)

    >
    > > and run it both as a script and an executable.

    >
    > I do have my script set up to find its arguments in sys.argv. And no,
    > I don't have that print screen.


    """print >> your_log_file,""" implies "print screen"?

    > As mentioned above, I don't have a
    > console window open when the exe runs, so I won't see any output from
    > it. I'll have to modify it to do that when I'm back at my work PC.
    >
    >
    >
    > > Have you tried running the executable stand-alone e.g. Start | Run,
    > > type in
    > > your_exe_file
    > > or whatever the argument(s) are?

    >
    > No, but that's a good idea. Why didn't I think of that!? (don't answer
    > that)


    OK, I won't :)
    >
    >
    > Thanks for the suggestions.


    You're welcome.
    John Machin, Dec 15, 2007
    #4
  5. Guest

    On Dec 14, 8:06 pm, John Machin <> wrote:

    <snipped>

    >
    > > The executable runs,

    >
    > how do you know it runs?
    >


    because the program's GUI appears on-screen.


    > > but no argument appears to get passed into it.

    >
    > appears??
    >



    Since the TO field doesn't get populated with the email address, it
    doesn't appear to receive it as an argument. Whereas if I run it as a
    script, it does receive the email address.

    Mike
    , Dec 15, 2007
    #5
  6. On Fri, 14 Dec 2007 16:38:28 -0800 (PST), declaimed
    the following in comp.lang.python:

    > The executable runs, but no argument appears to get passed into it. Of
    > course, I don't really know that for sure as the executable doesn't
    > redirect stdout/stderr. I tried doing something like this in the above
    > reg entry:
    >
    > cmd /C "c:\program files\myProg.exe %1"
    > "c:\program files\myProg.exe %1"
    > "c:\program files\myProg.exe"
    >

    What happens if you put the %1 OUTSIDE the quotes...

    cmd /c "c:\program files\myProg.exe" "%1"

    After all, if the quotes are being used to keep the command line seeing
    "program files" as a single term in the path, then your quotes are also
    treating "myProg.exe %1" as a single term.
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
    Dennis Lee Bieber, Dec 16, 2007
    #6
  7. Guest

    On Dec 15, 6:46 pm, Dennis Lee Bieber <> wrote:
    > On Fri, 14 Dec 2007 16:38:28 -0800 (PST), declaimed
    > the following in comp.lang.python:
    >
    > > The executable runs, but no argument appears to get passed into it. Of
    > > course, I don't really know that for sure as the executable doesn't
    > > redirect stdout/stderr. I tried doing something like this in the above
    > > reg entry:

    >
    > > cmd /C "c:\program files\myProg.exe %1"
    > > "c:\program files\myProg.exe %1"
    > > "c:\program files\myProg.exe"

    >
    > What happens if you put the %1 OUTSIDE the quotes...
    >
    > cmd /c "c:\program files\myProg.exe" "%1"
    >
    > After all, if the quotes are being used to keep the command line seeing
    > "program files" as a single term in the path, then your quotes are also
    > treating "myProg.exe %1" as a single term.
    > --
    > Wulfraed Dennis Lee Bieber KD6MOG
    >
    > HTTP://wlfraed.home.netcom.com/
    > (Bestiaria Support Staff: )
    > HTTP://www.bestiaria.com/


    This works:

    "c:\program files\myProg.exe" %1

    Thanks for the tip.
    , Dec 18, 2007
    #7
    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. Edward Diener
    Replies:
    14
    Views:
    4,881
    Josiah Carlson
    Apr 6, 2004
  2. Neo
    Replies:
    10
    Views:
    641
    sushant
    Jan 20, 2005
  3. tutmann
    Replies:
    4
    Views:
    427
  4. jmborr
    Replies:
    1
    Views:
    397
    Stargaming
    Nov 3, 2007
  5. oldyork90
    Replies:
    10
    Views:
    334
    Jorge
    Sep 27, 2008
Loading...

Share This Page