Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

running system commands, and getting return codes/status

by Anonymous Monk
on Nov 27, 2021 at 00:59 UTC ( #11139157=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Below is my code. It runs a backup program from a pTk GUI. My problem is at the 'system($cmd)' statement. The command gets executed before the message gets displayed in the text widget.

I want a message that tells * is being done, then when the process is done a message that says * is done along with relevant error codes.

Is there a better way to do this? And why are the messages displayed at the wrong time?

my @cmd = ""; push (@cmd , $prog_args , $fullf +ile2 , "/" ); my $cmd2 = join " " , @cmd +; $text -> delete ('1.0' , 'end' ); $text -> insert ('end' , "\n" ); $text -> insert ('end' , "THIS +OPERATION SHOULD TAKE 5 min. to 15 min. \n ", 'highlite' ); my $exit_status = system( +$cmd2 ); print "\$exit_statu +s at L1447 =: $exit_status\n"; if ( 0 == $exit_sta +tus ) { $text -> insert ('end' , "\n\n" ); $text -> insert ('end' , "DONE! \n", 'h +ighlite' ); }

Replies are listed 'Best First'.
Re: running system commands, and getting return codes/status
by tybalt89 (Prior) on Nov 27, 2021 at 01:49 UTC

    The system call prevents the event loop from running. You could put an $mw->update; call just before the system call, but the real way to handle this kind of thing is to use Tk::IO .

      tybalt: This is REALLY Tk::IO, and not IPC::IO, or *::IO ? I have not heard of Tk::IO. It's not in 'Learning PERL/Tk'. I and doing this from Windoze I need to switch system to view manpage.

        You do not need to switch systems to view the man page. Just use a browser to search "man tk::io". You'll not only find the man page but you'll find other useful references as well.

        I found Tk::IO with my manpage viewer. It looks extremely simple...

Re: running system commands, and getting return codes/status
by Marshall (Canon) on Nov 27, 2021 at 01:28 UTC
    Please post a short runnable example of your problem.
    Don't post your whole GUI code. Just create a small runnable file that demonstrates this issue.

    I don't understand this: "The command gets executed before the message gets displayed in the text widget.". What?

      The program I am working on is 1500L long. This is part of a subroutine that gets called. If I can get this to work, I have another subroutine with the same prob -- it executes a different command. This actually looks like a useful subroutine. (does such a codeblock/subroutine resist on 'monks/CPAN?)

        The program I am working on is ... long.

        Please see Short, Self-Contained, Correct Example for a longer discussion of what a "short runnable example" might look like. It is noted therein that just putting together such an example may clarify the problem enough for you so that you don't need to ask anyone else. Building an SSCCE should probably be considered a part of standard debugging praxis.


        Give a man a fish:  <%-{-{-{-<

Re: running system commands, and getting return codes/status
by Anonymous Monk on Nov 27, 2021 at 12:34 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11139157]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2022-08-09 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?