Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Home-built Twirling Bar Between Multiple System Calls

Reply
Thread Tools

Home-built Twirling Bar Between Multiple System Calls

 
 
foolishbrat
Guest
Posts: n/a
 
      05-06-2007
Dear all,
AFAIK, progress/twirling bar can only be applied under loops. For
example we can use Term:rogressBar or Smart::Comments. But is there
away to do it for system call like this:

__BEGIN__
#!/usr/bin/perl
system("code1.out param1 > output.txt");
system("code2.out param2 output.txt > output_final.txt");
__END__

How can I show progress/twirling Bar between first (code1) system call
and the second (code2) system call? Especially we don't know how long
each system call will take.

Preferrably not using external CPAN module (except pre-installed
module).

 
Reply With Quote
 
 
 
 
Martijn Lievaart
Guest
Posts: n/a
 
      05-06-2007
On Sun, 06 May 2007 08:20:03 -0700, foolishbrat wrote:

> Dear all,
> AFAIK, progress/twirling bar can only be applied under loops. For
> example we can use Term:rogressBar or Smart::Comments. But is there
> away to do it for system call like this:
>
> __BEGIN__
> #!/usr/bin/perl
> system("code1.out param1 > output.txt"); system("code2.out param2
> output.txt > output_final.txt"); __END__
>
> How can I show progress/twirling Bar between first (code1) system call
> and the second (code2) system call? Especially we don't know how long
> each system call will take.
>
> Preferrably not using external CPAN module (except pre-installed
> module).


Easy. Fork to do the system call. In the parent show the progress bar and
check with wait_pid if the child is ready.

May or may not work on Windows, though, no idea really.

HTH,
M4
 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      05-06-2007
Martijn Lievaart wrote:
> On Sun, 06 May 2007 08:20:03 -0700, foolishbrat wrote:
>> #!/usr/bin/perl
>> system("code1.out param1 > output.txt");
>> system("code2.out param2 output.txt > output_final.txt");
>>
>> How can I show progress/twirling Bar between first (code1) system call
>> and the second (code2) system call? Especially we don't know how long
>> each system call will take.

>
> Easy. Fork to do the system call. In the parent show the progress bar and
> check with wait_pid if the child is ready.
>
> May or may not work on Windows, though, no idea really.


#!/usr/bin/perl
use strict; use warnings;
$|++;

our $child_pid; # Holds PID while child is running
$SIG{CHLD} = sub { $child_pid = 0; }; # When child has exited
# That works for POSIX-like systems (Linux, Cygwin), but not Windows-XP

my $cmd = 'sleep 12'; # Example for code1.out
if ($child_pid = fork) {
print "Parent waiting for child $child_pid to finish: ";
my $count;
while ($child_pid) {
printf "%s%4d\b\b\b\b\b", substr('-/|\\',++$count%4,1), $count;
sleep 1;
}
print "Done!\n";
} else {
print "Child $$ running `$cmd`\n";
exec $cmd; # code1.out runs here
}
system "echo code2.out runs here";
print "Finished\n";

-Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are system calls sometimes costlier than library calls? Richard Tobin C Programming 24 11-11-2007 08:52 AM
disable title bar, status bar, and address bar of a window Matt HTML 9 08-23-2004 07:49 PM
javascript to disable the title bar, status bar, and address bar of a window Matt Javascript 9 08-23-2004 01:23 PM
Re: disable title bar, status bar, and address bar of a browser window John Hann ASP .Net 0 08-21-2004 05:07 AM
disable title bar, status bar, and address bar of a browser window Matt ASP .Net 0 08-21-2004 03:50 AM



Advertisments