windows background process

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

    #1

    windows background process

    Hi,

    I am using Python 2.4.4 on Windows XP SP2.

    I am trying to start a process (infinite loop application) in the
    background and I've tried several options and none of them seem to
    work.

    Any help would be much appreciated.

    Thanks,
    P

    1.
    # This works on PythonWin interactive window, but the python.exe
    process hangs until mycmd.exe process dies
    >>os.popen("myc md.exe myargs") # works
    if __name__ == '__main__':
    os.popen("mycmd .exe myargs") # hangs

    2.
    >>os.system("my cmd.exe myargs") # hangs, as expected
    3.
    os.spawnl(os.P_ NOWAIT, 'mycmd.exe', 'myargs') # mycmd.exe not started
    os.spawnv(os.P_ NOWAIT, 'mycmd.exe', tuple('myargs') ) # mycmd.exe not
    started

    4.
    # Works, but not portable. My code is expected to run on *nix later on
    os.system('star t /B "dummy title" "mycmd.exe" myargs')

  • Podi

    #2
    Re: windows background process

    Some update...

    I just found out that the following seems to work,

    import subprocess
    subprocess.Pope n(' myargs', executable='myc md.exe')

    However, it does not work with "my path\\mycmd.exe "

    subprocess.Pope n(' myargs', executable='"my path\\mycmd.exe "') # error

    Comment

    • Gabriel Genellina

      #3
      Re: windows background process

      At Wednesday 22/11/2006 21:27, Podi wrote:
      >3.
      >os.spawnl(os.P _NOWAIT, 'mycmd.exe', 'myargs') # mycmd.exe not started
      >os.spawnv(os.P _NOWAIT, 'mycmd.exe', tuple('myargs') ) # mycmd.exe not
      >started
      os.spawnl(os.P_ NOWAIT, 'mycmd.exe', 'mycmd.exe', 'first_arg', 'second_arg')
      That is, you must provide explicitely the value for argv[0] (executable)
      Remember to quote appropiately any parameter with embedded spaces
      (including the executable). On Python 2.5 you could use subprocess.list 2cmdline


      --
      Gabriel Genellina
      Softlab SRL

      _______________ _______________ _______________ _____
      Correo Yahoo!
      Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
      ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

      Comment

      • Gabriel Genellina

        #4
        Re: windows background process

        At Wednesday 22/11/2006 22:05, Podi wrote:
        >Some update...
        >
        >I just found out that the following seems to work,
        >
        >import subprocess
        >subprocess.Pop en(' myargs', executable='myc md.exe')
        >
        >However, it does not work with "my path\\mycmd.exe "
        >
        >subprocess.Pop en(' myargs', executable='"my path\\mycmd.exe "') # error
        Same as before, executable should be the first argument, so it's seldom used.
        Try subprocess.Pope n((full_path_to _mycmd, full_path_to_my cmd, arg1, arg2))


        --
        Gabriel Genellina
        Softlab SRL

        _______________ _______________ _______________ _____
        Correo Yahoo!
        Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
        ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

        Comment

        • Podi

          #5
          Re: windows background process


          Gabriel Genellina wrote:
          os.spawnl(os.P_ NOWAIT, 'mycmd.exe', 'mycmd.exe', 'first_arg', 'second_arg')
          That is, you must provide explicitely the value for argv[0] (executable)
          Remember to quote appropiately any parameter with embedded spaces
          (including the executable). On Python 2.5 you could use subprocess.list 2cmdline
          >
          Right, this works. Before, I didn't realize that the full path goes to
          the 2nd and 3rd argument of spawnl.

          Thanks for the help.
          P

          Comment

          Working...