FAQ
Hi,

I am new to python programing. I have created one small application ,

application developed in python Tkinter GUI, My application having
install button

when user click install, It will start one GUI installation script and
exit my application

This my task.. The problem was the installation script started but
control will be transfered to

other window ... when installation finished the GUI application will be closed..

code:

os.system("ls -l") & root.destroy

when execute a command "ls -l " and application will be closed

But

os.system("top") & root.destroy

Control will the transferred to the other-window, "top" closed means
application will be closed.. plz..help me..

I checked also the command as background process.. like os.system("top
&") & root.destroy


Advance thanks

Regards
Ganesh.




--
Did I learn something today? If not, I wasted it.

Search Discussions

  • ALAN GAULD at Feb 19, 2011 at 10:04 am

    when user click install, It will start one GUI installation script and
    exit my application

    This my task.. The problem was the installation script started but
    control will be transfered to

    other window ... when installation finished the GUI application will be
    closed..

    code:

    os.system("ls -l") & root.destroy
    First question is, why are you using the bitwise and operator to manage
    execution status. This is Python not C. Use clear logic that erflects
    what you are trying to do.( Especially if you only post code fragments.)

    if os.system('ls -l') != 0 : root.destroy()

    Is much more obvious in intent.
    when execute a command "ls -l " and application will be closed
    Only if os.system returns an error code
    os.system("top") & root.destroy

    Control will the transferred to the other-window, "top" closed means
    application will be closed.. plz..help me..
    I have no idea what other window you are referring to. Is it the
    OS console that top runs in? Have you checked the return code
    of os.system to see if it returns cleanly (ie a 0) or if it returns an error?

    You might find it better to use the subprocess module instead of
    os.system. There is more flexibilityy and control available there.
    I checked also the command as background process.. like os.system("top
    &") & root.destroy
    And what happened?

    We need a bit more context and you need to do a bity more debugging.
    Starting with getting rid of the bitwise and "trick" from C. All it does
    here is make it hard to understand whats happening.

    HTH,

    Alan G.
    Author of the Learn to Program web site
    http://www.alan-g.me.uk/
  • Stephen Hansen at Feb 19, 2011 at 4:17 pm

    On 2/19/11 1:44 AM, Ganesh Kumar wrote:
    os.system("ls -l") & root.destroy
    "&" here doesn't do what you think it does. Its a bitwise AND operator,
    which is not the same thing as you may be expecting from other languages.

    In Python, you'd do something more like:

    os.system("ls -l") and root.destroy()

    But that's bad Python. First, let's look at what os.system actually returns:
    import os
    help(os.system)
    system(...)
    system(command) -> exit_status

    Execute the command (a string) in a subshell.

    Now, an exit status of 0 is actually generally considered a success,
    while 1-200odd is a failure.

    Now, if you want to run 'root.destroy()' if and only if the 'ls -l'
    command fails, you could do the above with an 'and'. Python DOES
    short-circuit its logical AND's, so the root.destroy() will NOT be run
    if ls -l succeeds (returns 0)... but really.

    That's _very_ cryptic.

    Its much better to do:

    if os.system("ls -l") != 0:
    root.destroy()

    (You could simply say 'if not os.system("ls -l")', but in this context
    where the more unusual behavior of '0 is true, >0 is false' which is
    opposite of what is normal in Python, I prefer to explicitly spell it out)

    If you instead mean the "&" to simply separate the statements, so that
    after the os.system is done, then regardless of the outcome root.destroy
    is called-- then... just separate the statements.

    os.system("ls -l")
    root.destroy()

    You can use them on the same line with a semicolon if you really must.
    But don't do that. :-)

    Now, all of that said -- I'm not sure what exactly is going WRONG with
    your program. You said GUI, and perhaps that's the problem? If you are
    calling a unix interactive command line program from within a GUI
    context, things are quite likely to go wrong unless you do a lot of
    extra work. Are you expecting a new console window to pop up for 'top'
    and for that to run on its own? If so -- that won't happen on its own or
    with a single function call sort of easy way.

    What OS are you on? What are you actually trying to do here?

    --

    Stephen Hansen
    ... Also: Ixokai
    ... Mail: me+list/python (AT) ixokai (DOT) io
    ... Blog: http://meh.ixokai.io/

    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: signature.asc
    Type: application/pgp-signature
    Size: 487 bytes
    Desc: OpenPGP digital signature
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110219/eb342d4f/attachment.pgp>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedFeb 19, '11 at 9:44a
activeFeb 19, '11 at 4:17p
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase