• subprocess.Popen does not launch audacity

    From Tim Johnson@thjmmj15@gmail.com to comp.lang.python on Fri Jan 10 10:15:50 2025
    From Newsgroup: comp.lang.python

    Using Python 3.12.3 on Ubuntu 24.04

    I've converted a legacy python2 script to python3. All went well.
    However, a glitch from python2 remains.

    The script uses dmenu to create menus to pick applications. Applications
    are then invoked from python

    using subprocess.Popen(). I have never been able to successfully launch audacity using this approach,

    which does work for other apps.

    I can launch audacity successfully using dmenu_run (on its own, outside
    of the script)

    Below is the pertinent code:

     Popen(choice, stdout=PIPE, stderr=PIPE,
                      stdin=PIPE, close_fds=True)

    My guess is my argument list is either insufficient or an argument is
    causing the problem, but am unsure of which.

    I have been retired from python programming for ten years, and am pretty rusty, but it is still fun. There are plenty

    of other ways to successfully launch audacity but it would be great to
    make it work from this script.

    Thanks in advance

    Tim

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From MRAB@python@mrabarnett.plus.com to comp.lang.python on Fri Jan 10 20:32:08 2025
    From Newsgroup: comp.lang.python

    On 2025-01-10 19:15, Tim Johnson via Python-list wrote:
    Using Python 3.12.3 on Ubuntu 24.04

    I've converted a legacy python2 script to python3. All went well.
    However, a glitch from python2 remains.

    The script uses dmenu to create menus to pick applications. Applications
    are then invoked from python

    using subprocess.Popen(). I have never been able to successfully launch audacity using this approach,

    which does work for other apps.

    I can launch audacity successfully using dmenu_run (on its own, outside
    of the script)

    Below is the pertinent code:

     Popen(choice, stdout=PIPE, stderr=PIPE,
                      stdin=PIPE, close_fds=True)

    My guess is my argument list is either insufficient or an argument is
    causing the problem, but am unsure of which.

    I have been retired from python programming for ten years, and am pretty rusty, but it is still fun. There are plenty

    of other ways to successfully launch audacity but it would be great to
    make it work from this script.


    What is the value of 'choice'?

    You could try printing out the value of 'choice' for one that works and
    the one that doesn't and then try them again interactively from the
    Python prompt with the given values. That should eliminate all but the essential code for easier debugging.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Tim Johnson@thjmmj15@gmail.com to comp.lang.python on Fri Jan 10 12:00:02 2025
    From Newsgroup: comp.lang.python


    On 1/10/25 11:32, MRAB via Python-list wrote:
    ,,, snipped

    Below is the pertinent code:

       Popen(choice, stdout=PIPE, stderr=PIPE,
                        stdin=PIPE, close_fds=True)

    My guess is my argument list is either insufficient or an argument is
    causing the problem, but am unsure of which.

    I have been retired from python programming for ten years, and am pretty
    rusty, but it is still fun. There are plenty

    of other ways to successfully launch audacity but it would be great to
    make it work from this script.


    What is the value of 'choice'?

    You could try printing out the value of 'choice' for one that works
    and the one that doesn't and then try them again interactively from
    the Python prompt with the given values. That should eliminate all but
    the essential code for easier debugging.

    choice is /usr/local/bin/audacity, which is the correct path for
    audacity on my system. As far as I can see, that string has no hidden bytes.

    Invoking /usr/local/bin/audacity from the command line launches audacity
    and so does choosing  with dmenu_run. which -a audacity shows only that
    item.

    Maybe I need to isolate the function call and start stripping out
    parameters. I should have time to do that later today.

    Thanks

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Left Right@olegsivokon@gmail.com to comp.lang.python on Fri Jan 10 22:39:35 2025
    From Newsgroup: comp.lang.python

    I just tried this:
    >>> import subprocess
    >>> subprocess.run('which audacity', shell=True)
    /usr/bin/audacity
    CompletedProcess(args='which audacity', returncode=0)
    >>> proc = subprocess.Popen('/usr/bin/audacity',
    stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, close_fds=True)
    >>> proc.returncode
    >>> proc.pid
    53308
    >>> proc.kill()
    >>> proc.returncode
    0
    >>>
    And I saw the interface of the program... So, in principle, what you
    tried should work.
    What happens if in a separate terminal you try:
    $ ps auxwww | grep audacity?
    Are there any processes running?
    If your script fails, what is the error?
    If it doesn't, can you run this:
    $strace python ./audacity-test.py
    where audacity-test.py looks like this:
    import subprocess
    proc = subprocess.Popen('/usr/local/bin/audacity',
    stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, close_fds=True)
    print(proc.returncode)
    print(proc.pid)
    proc.wait()
    proc.kill()
    print(proc.returncode)
    Then, you should see something like:
    clone(child_stack=NULL,
    flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f377d83b750) = 53932
    close(10) = 0
    close(8) = 0
    close(6) = 0
    close(3) = 0
    read(9, "", 50000) = 0
    close(9) = 0
    write(1, "None\n", 5None
    ) = 5
    write(1, "53932\n", 653932
    ) = 6
    wait4(53932,
    (the process id you are waiting for is going to be different of
    course, but the important part is that you find the clone() call that
    returns the process id your code is waiting on.)
    And, if it doesn't look like the above, then show what *does* it look like.
    On Fri, Jan 10, 2025 at 10:03 PM Tim Johnson via Python-list <python-list@python.org> wrote:


    On 1/10/25 11:32, MRAB via Python-list wrote:
    ,,, snipped

    Below is the pertinent code:

    Popen(choice, stdout=PIPE, stderr=PIPE,
    stdin=PIPE, close_fds=True)

    My guess is my argument list is either insufficient or an argument is
    causing the problem, but am unsure of which.

    I have been retired from python programming for ten years, and am pretty >> rusty, but it is still fun. There are plenty

    of other ways to successfully launch audacity but it would be great to
    make it work from this script.


    What is the value of 'choice'?

    You could try printing out the value of 'choice' for one that works
    and the one that doesn't and then try them again interactively from
    the Python prompt with the given values. That should eliminate all but
    the essential code for easier debugging.

    choice is /usr/local/bin/audacity, which is the correct path for
    audacity on my system. As far as I can see, that string has no hidden bytes.

    Invoking /usr/local/bin/audacity from the command line launches audacity
    and so does choosing with dmenu_run. which -a audacity shows only that
    item.

    Maybe I need to isolate the function call and start stripping out
    parameters. I should have time to do that later today.

    Thanks

    --
    https://mail.python.org/mailman/listinfo/python-list
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Gilmeh Serda@gilmeh.serda@nothing.here.invalid to comp.lang.python on Fri Jan 10 21:46:53 2025
    From Newsgroup: comp.lang.python

    On Fri, 10 Jan 2025 10:15:50 -0900, Tim Johnson wrote:

    using subprocess.Popen(). I have never been able to successfully launch audacity using this approach,

    Some thoughts you might try:

    What does your .desktop file say (launcher menu)? Assuming you have it installed that way. Or is it a flatpak or something?

    Read the .desktop file so you use the exact same command. It might not be
    what you expected. It might need some option or it's a different command
    from what you thought.

    Or, try the command you used, but at the prompt, does that work? Get any errors?

    Or try something simpler, like without PIPEs, sort of back to basics, as
    it were.

    What's in "choice" variable? Only the (correct) command, or something else also? Test it to be sure, it's easy to add things that shouldn't be there
    in a moment of a brain fatigue.

    Does it work outside your script file? For instance by invoking the Python prompt and try there?
    --
    Gilmeh

    They are relatively good but absolutely terrible. -- Alan Kay, commenting
    on Apollos
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Thomas Passin@list1@tompassin.net to comp.lang.python on Fri Jan 10 16:53:14 2025
    From Newsgroup: comp.lang.python

    On 1/10/2025 4:00 PM, Tim Johnson via Python-list wrote:

    On 1/10/25 11:32, MRAB via Python-list wrote:
    ,,, snipped

    Below is the pertinent code:

       Popen(choice, stdout=PIPE, stderr=PIPE,
                        stdin=PIPE, close_fds=True)

    My guess is my argument list is either insufficient or an argument is
    causing the problem, but am unsure of which.

    I have been retired from python programming for ten years, and am pretty >>> rusty, but it is still fun. There are plenty

    of other ways to successfully launch audacity but it would be great to
    make it work from this script.


    What is the value of 'choice'?

    You could try printing out the value of 'choice' for one that works
    and the one that doesn't and then try them again interactively from
    the Python prompt with the given values. That should eliminate all but
    the essential code for easier debugging.

    choice is /usr/local/bin/audacity, which is the correct path for
    audacity on my system. As far as I can see, that string has no hidden
    bytes.

    Invoking /usr/local/bin/audacity from the command line launches audacity
    and so does choosing  with dmenu_run. which -a audacity shows only that item.

    Maybe I need to isolate the function call and start stripping out parameters. I should have time to do that later today.

    I don't know why you would want to redirect stdin, etc. It's a GUI application.

    This worked for me in a Python session on EndeavourOS, python 3.13.1:

    from subprocess import run
    run('/usr/bin/audacity')


    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Tim Johnson@thjmmj15@gmail.com to comp.lang.python on Fri Jan 10 14:21:21 2025
    From Newsgroup: comp.lang.python


    On 1/10/25 12:53, Thomas Passin via Python-list wrote:
    On 1/10/2025 4:00 PM, Tim Johnson via Python-list wrote:

    On 1/10/25 11:32, MRAB via Python-list wrote:
    ,,, snipped

    Below is the pertinent code:

       Popen(choice, stdout=PIPE, stderr=PIPE,
                        stdin=PIPE, close_fds=True)

    My guess is my argument list is either insufficient or an argument is
    causing the problem, but am unsure of which.

    I have been retired from python programming for ten years, and am
    pretty
    rusty, but it is still fun. There are plenty

    of other ways to successfully launch audacity but it would be great to >>>> make it work from this script.


    What is the value of 'choice'?

    You could try printing out the value of 'choice' for one that works
    and the one that doesn't and then try them again interactively from
    the Python prompt with the given values. That should eliminate all
    but the essential code for easier debugging.

    choice is /usr/local/bin/audacity, which is the correct path for
    audacity on my system. As far as I can see, that string has no hidden
    bytes.

    Invoking /usr/local/bin/audacity from the command line launches
    audacity and so does choosing  with dmenu_run. which -a audacity
    shows only that item.

    Maybe I need to isolate the function call and start stripping out
    parameters. I should have time to do that later today.

    I don't know why you would want to redirect stdin, etc.  It's a GUI application.

    This worked for me in a Python session on EndeavourOS, python 3.13.1:

    from subprocess import run
    run('/usr/bin/audacity')

    You're right as I suspected. The input files that I am using need a flag
    field to indicate whether the target

    is a gui or terminal app. Removing the pipe parameters gave me audacity
    just fine. Time to roll up my sleeves

    and get to work adding the relevant code. Beats shoveling snow. :)

    Thanks everybody.



    --- Synchronet 3.20a-Linux NewsLink 1.114