Re: [Cocoadialog-users] perl and bash scripts
Status: Beta
Brought to you by:
sporkstorms
From: Mark A. S. <ma...@sp...> - 2005-02-12 20:18:04
|
Hello. This problem isn't so much about the way Perl works, as it is about the way Unix works. The "Unix way" to do this sort of thing is to execute separate scripts, one after another, and pipe their results to the next program. The way you "return" values in the shell is to print them to stdout. Example: script1.sh | script2.pl | script3.sh | final_script.sh Where each of those scripts does one specific thing. Now if your script doesn't make sense to be split into multiple scripts, there are a couple of alternatives - probably easier to implement as well. You can just catch the stdout of a program with backticks. The syntax is the same in Perl (see "perldoc perlop") and bash (see "man bash"). Example: ------- main_program.sh -------- #!/bin/bash something=`perl hello.pl mark` echo "the Perl script wanted me to tell you $something" ----- snip ----- ---- hello.pl ---- #!/usr/bin/perl -w use strict; my $name = shift @ARGV; print "Hello ", $name, "\n"; --- snip --- Running main_program.sh will print to stdout "Hello mark". A third, and probably best solution is to just rewrite your scripts entirely in bash or entirely in Perl - whichever you're more comfortable with. I hope this helps. If not, let me know more specifically with examples what you're trying to do. - mark On Feb 11, 2005, at 5:40 PM, Heather Emmerton wrote: > Hi, > I don't know how regularly this list is monitored, but > thought I would try anyway... > I am using CocoaDialog to GUI-up some unix-based > procedures. I am hoping to use several of the example > functions in one 'master script'. Specifically I am > using msgboxes and the perl input text box. I'm a > novice perl user and I'm wondering if anyone can give > me any tips (or confirm it's even possible) to > pass variable values back UP from my perl input text- > box 'subroutine' to the parent bash script that called > it. I have tried to very crudely modify an ENV variable > in perl and read it from the bash script, but the > bash script is not reading the modified value. > I have been calling the perl script command-line style > from my bash script as follow: > perl myscript.pl > I would suppose there is a better way of using a perl > subroutine, but as a novice perl user (read 'never > used perl before needing the perl textbox script') > I don't know how to do this (I'll be buying a > perl book this weeke > nd to ameliorate this situation) > I don't think I can simply use a return value from > a perl subroutine, because I need to pass longer > values, specifically the string from the text > input box. > If anyone has a suggestion of how this could be > accomplished, your advice would be MUCH appreciated. > Thanks in advance, > Heather > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real > users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Cocoadialog-users mailing list > Coc...@li... > https://lists.sourceforge.net/lists/listinfo/cocoadialog-users > |