Launching scripts in Ubuntu ?

Discussion in 'Python' started by Stef Mientki, Oct 14, 2008.

  1. Stef Mientki

    Stef Mientki Guest

    hello,

    I'm not familiar with Linux / Ubuntu,
    still trying to get my application working under these operating systems.

    I've a script "file_support.py",
    now when I'm in Ubuntu, open a command window and go to the directory
    where that file is,
    I can launch the script with :
    "python file_support.py"
    and it works great

    Now when I want to run the script from another script, let's call it "
    test.py"
    where this is the contents of test.py:

    import subprocess
    subprocess.Popen ( [ 'python', 'file_support.py', ] )

    The script "file_support" is executed correctly,
    but the python interpreter is not closed,
    I've to close it manual by pressing ENTER.

    What should I change ?

    thanks,
    Stef Mientki
     
    Stef Mientki, Oct 14, 2008
    #1
    1. Advertising

  2. Stef Mientki wrote:

    > hello,
    >
    > I'm not familiar with Linux / Ubuntu,
    > still trying to get my application working under these operating systems.
    >
    > I've a script "file_support.py",
    > now when I'm in Ubuntu, open a command window and go to the directory
    > where that file is,
    > I can launch the script with :
    > "python file_support.py"
    > and it works great
    >
    > Now when I want to run the script from another script, let's call it "
    > test.py"
    > where this is the contents of test.py:
    >
    > import subprocess
    > subprocess.Popen ( [ 'python', 'file_support.py', ] )
    >
    > The script "file_support" is executed correctly,
    > but the python interpreter is not closed,
    > I've to close it manual by pressing ENTER.


    What do you mean "it's not closed"? Which window is taking the enter, and
    how do you run test.py?

    Diez
     
    Diez B. Roggisch, Oct 14, 2008
    #2
    1. Advertising

  3. Stef Mientki

    Stef Mientki Guest

    Diez B. Roggisch wrote:
    > Stef Mientki wrote:
    >
    >
    >> hello,
    >>
    >> I'm not familiar with Linux / Ubuntu,
    >> still trying to get my application working under these operating systems.
    >>
    >> I've a script "file_support.py",
    >> now when I'm in Ubuntu, open a command window and go to the directory
    >> where that file is,
    >> I can launch the script with :
    >> "python file_support.py"
    >> and it works great
    >>
    >> Now when I want to run the script from another script, let's call it "
    >> test.py"
    >> where this is the contents of test.py:
    >>
    >> import subprocess
    >> subprocess.Popen ( [ 'python', 'file_support.py', ] )
    >>
    >> The script "file_support" is executed correctly,
    >> but the python interpreter is not closed,
    >> I've to close it manual by pressing ENTER.
    >>

    >
    > What do you mean "it's not closed"?

    well the command prompt (if it is called that way in Linus) is not returned.

    When I run file_support, the command window looks like this
    >>>python file_support.py

    ...... all kinds of output
    >>>


    When I run test.py (which calls fie_support) , I get this
    >>>python test.py

    ..... all kinds of output (the same as before)

    Now I've to explicitly press an enter to get the command prompt back.
    This might not sound important,
    but the problem is somewhat more complex,
    all these scripts are ran from another program,
    and although everything works fine under windows,
    the program hangs on Ubuntu.
    So I guess that this is the (first) problem to solve.

    thanks,
    Stef





    > Which window is taking the enter, and
    > how do you run test.py?
    >
    > Diez
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
     
    Stef Mientki, Oct 14, 2008
    #3
  4. >> What do you mean "it's not closed"?
    > well the command prompt (if it is called that way in Linus) is not
    > returned.
    >
    > When I run file_support, the command window looks like this
    > >>>python file_support.py

    > ..... all kinds of output
    > >>>

    >
    > When I run test.py (which calls fie_support) , I get this
    > >>>python test.py

    > .... all kinds of output (the same as before)
    >
    > Now I've to explicitly press an enter to get the command prompt back.
    > This might not sound important,
    > but the problem is somewhat more complex,
    > all these scripts are ran from another program,
    > and although everything works fine under windows,
    > the program hangs on Ubuntu.
    > So I guess that this is the (first) problem to solve.


    This looks odd. I've never seen a *shell* display ">>>" as prompt. So it
    looks as if you mix stuff between the shell (bash, tcsh, whatever) and
    python in the above. Are you *inside* the python interpreter already when
    typing "python test.py"?

    And if *not*, does typing e.g. "ls <return>" work for you, right after the
    test.py is run? Then there is no "getting back of the prompt", it's just
    that a last newline is .. well, not even missing, just not printed.
    Consider this (I use $ for the shellpromt):

    $ python -c "import sys;sys.stdout.write('hello')"
    hello$

    Additonally, you might want to check out the Popen-object-reference for the
    wait-call, but actually that shouldn't change anything with regards to
    pressing enter or not.

    Diez
     
    Diez B. Roggisch, Oct 14, 2008
    #4
  5. Stef Mientki

    Stef Mientki Guest

    Diez B. Roggisch wrote:
    >>> What do you mean "it's not closed"?
    >>>

    >> well the command prompt (if it is called that way in Linus) is not
    >> returned.
    >>
    >> When I run file_support, the command window looks like this
    >> >>>python file_support.py

    >> ..... all kinds of output
    >> >>>

    >>
    >> When I run test.py (which calls fie_support) , I get this
    >> >>>python test.py

    >> .... all kinds of output (the same as before)
    >>
    >> Now I've to explicitly press an enter to get the command prompt back.
    >> This might not sound important,
    >> but the problem is somewhat more complex,
    >> all these scripts are ran from another program,
    >> and although everything works fine under windows,
    >> the program hangs on Ubuntu.
    >> So I guess that this is the (first) problem to solve.
    >>

    >
    > This looks odd. I've never seen a *shell* display ">>>" as prompt.

    ">>>" stands for:
    stef@stef-desktop:/media/disk/Data_Python_25/support$

    > So it
    > looks as if you mix stuff between the shell (bash, tcsh, whatever) and
    > python in the above. Are you *inside* the python interpreter already when
    > typing "python test.py"?
    >

    So no
    > And if *not*, does typing e.g. "ls <return>" work for you, right after the
    > test.py is run?

    yes it does
    > Then there is no "getting back of the prompt", it's just
    > that a last newline is .. well, not even missing, just not printed.
    > Consider this (I use $ for the shellpromt):
    >
    > $ python -c "import sys;sys.stdout.write('hello')"
    > hello$
    >
    > Additonally, you might want to check out the Popen-object-reference for the
    > wait-call, but actually that shouldn't change anything with regards to
    > pressing enter or not.
    >

    ok It seems to be solved now,
    In creating a small example to emphasize the problem,
    I found the difference between Win and Linux:
    In windows "shell=True" and in Linux "shell=False"
    PID = subprocess.Popen( arguments,
    cwd = cwd ,
    stdout = subprocess.PIPE,
    stderr = subprocess.PIPE,
    shell = ( os.name == 'nt') )
    so the above statement seems (at least for the moment) solve all the
    problems.

    thank you all,
    Stef
     
    Stef Mientki, Oct 14, 2008
    #5
  6. En Tue, 14 Oct 2008 10:46:34 -0300, Stef Mientki <>
    escribió:

    >>> well the command prompt (if it is called that way in Linus) is not
    >>> returned.
    >>>
    >>> When I run file_support, the command window looks like this
    >>> >>>python file_support.py
    >>> ..... all kinds of output
    >>> >>>
    >>>
    >>> When I run test.py (which calls fie_support) , I get this
    >>> >>>python test.py
    >>> .... all kinds of output (the same as before)
    >>>
    >>> Now I've to explicitly press an enter to get the command prompt back.


    > ok It seems to be solved now,
    > In creating a small example to emphasize the problem,
    > I found the difference between Win and Linux:
    > In windows "shell=True" and in Linux "shell=False"
    > PID = subprocess.Popen( arguments,
    > cwd = cwd ,
    > stdout = subprocess.PIPE,
    > stderr = subprocess.PIPE,
    > shell = ( os.name == 'nt') )
    > so the above statement seems (at least for the moment) solve all the
    > problems.


    I'd say there is no problem. It just *appears* to be one. The first
    program finishes, and the shell displays its prompt, while the child is
    still outputting things. I bet you can see the stef@stef-desktop...$
    somewhere in the output.

    It's like executing:
    $ ls&
    the shell prompt is shown as soon as the ls (background) process starts,
    but gets lost in the output.

    > Diez B. Roggisch wrote:
    >> Additonally, you might want to check out the Popen-object-reference for
    >> the
    >> wait-call, but actually that shouldn't change anything with regards to
    >> pressing enter or not.


    Calling wait in the parent script would prevent it to finish before the
    child, avoiding the issue.

    --
    Gabriel Genellina
     
    Gabriel Genellina, Oct 14, 2008
    #6
    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. Jan Danielsson
    Replies:
    8
    Views:
    633
    Mike Meyer
    Jul 22, 2005
  2. Jp Calderone
    Replies:
    0
    Views:
    462
    Jp Calderone
    Jul 21, 2005
  3. SPE - Stani's Python Editor
    Replies:
    1
    Views:
    459
    SPE - Stani's Python Editor
    Apr 29, 2008
  4. davidj411
    Replies:
    0
    Views:
    520
    davidj411
    Jun 27, 2008
  5. Replies:
    13
    Views:
    537
    Anno Siegel
    Sep 10, 2007
Loading...

Share This Page