Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Append a tools status to the command line..

by Rhodium (Scribe)
on Apr 14, 2002 at 16:04 UTC ( [id://158943]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks,
I have a neat little perl wrapper for a tool that we use all the time. It basically checks syntax, and does some verification before this tool lauches. When this tool launches we can run this other little command line csh script which will tell you it's status. Here is the little csh code
#!/bin/csh set logfile = `/bin/ls -c1tr *.log | tail -1` set total = `cat jxrun.stg | awk ' {print $4} '` set stage = `grep STAGE $logfile | tail -1 | awk ' {print $4} '` echo "" echo "Total number of Stages .... $total" echo "Job currently at Stage .... $stage" echo "scale=2" > .bcinput echo "$stage/$total*100" >> .bcinput echo "quit" >> .bcinput echo "" echo "Your Dracula Job is" `bc .bcinput` "percent Complete." echo "" if ( `bc .bcinput` == 100.00 ) then echo "The following line should say THE END OF PROGRAM" echo "" tail -2 $logfile echo "If not, your job is still on the last stage." echo "" endif
Now obviously I can do this in perl. But I was thinking hey woulnd't this be cool to just append it's progress to your prompt line.. So you always know where it's at? So does anyone know how to set the prompt (depending on there shell) to monitor somthing like this? Any Ideas?
Thanks so much!!

Rhodium

The <it>seeker</it> of perl wisdom.

Replies are listed 'Best First'.
Re: Append a tools status to the command line..
by Kanji (Parson) on Apr 14, 2002 at 16:43 UTC

    To keep this on topic, if you use the the Perl shell (alt., but not to be confused with the other Perl shells), you should be able to do something like ...

    # UNTESTED! $Psh::prompt = sub { my $progress = get_progress(); "($progress%) psh\$ "; }

    ... where get_progress() does something similar to your csh code.

        --k.


Re: Append a tools status to the command line..
by lhoward (Vicar) on Apr 14, 2002 at 21:20 UTC
    This doesn't work in every OS (it does work in Linux, but I think it doesn't work in solaris)... you can set $0, which will influence what you see when you do a ps:
    #!/bin/perl -w use strict; my $pr=$0; for(1..10){ $0=$pr." processing $_"; sleep 5; }
    when I run this code on my linux box and do a ps -ef to see what # it is currently on in the loop....
Re: Append a tools status to the command line..
by stephen (Priest) on Apr 15, 2002 at 02:37 UTC

    Changing the command line usually involves changing an environment variable in your shell. Since processes can't change each others' environment variables directly, you can't change a prompt from another process.

    What I'd recommend is having the tool wrapper write a status line to a file, then using shell-escapes to insert a `cat /whatever/the/file/is` into your prompt. See your shell documentation for details.

    stephen

Re: Append a tools status to the command line..
by kappa (Chaplain) on Apr 16, 2002 at 14:47 UTC
    This can be accomplished via special buffer file, as stephen and others sugessted. The long-running program should update the file periodically, and the shell will read the file and insert the contents into the prompt.

    Another way will let you avoid periodic writes of current progress and employs fifos or named pipes. This isn't easier to implement and won't probably run much faster, but is indeed a different way to do it.

    You should arrange a progress-writer thread (or process, but this will make the whole thing even more evil) which will just write current progress into a fifo in an endless loop. Remember, if there's no reader on the other end of the fifo, then the writer will block until the reader emerges.

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-16 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found