Re: Getting pid and error from do shell script
Re: Getting pid and error from do shell script
- Subject: Re: Getting pid and error from do shell script
- From: David Simerly <email@hidden>
- Date: Tue, 26 Dec 2006 08:56:13 -0800
- Thread-topic: Getting pid and error from do shell script
- Url: http://www.digital-native.com
Title: Re: Getting pid and error from do shell script
On 12/23/06 1:47 PM, "Luther Fuller" <email@hidden> wrote:
My problem is that I also need to get a pid from the second script if
the user does NOT click Cancel. I have read TN2065 "do shell script
in AppleScript" for the third time, but it offers no understanding of
this problem. (It recommends that I "See the sh man page under
"Redirection" for more details." ... but there is no man page for sh!)
Well, first, if the hdiutil returns the pid, then it will be returned by do shell script. So you can do something like:
set the_pid to do shell script quoted form of ( "hdiutil convert " & inFile & " -format UDZO -encryption -o " & outFile )
Not having scripted hdiutil in several years, I don’t recall whether this will work. Also, whatever the command, I recommend using “quoted form of” because it takes care of any spaces or other unquoted chars that will make BSD choke.
If hdiutil does not return its pid, then you’ll need to use redirection (aka “piping”). So follow-up your initial do shell script call to hdiutil, with a second call that goes something like:
set the_pid to do shell script “ps –acx | grep hdiutil”
The redirection operation in this case is the vertical bar “|” (or pipe), which redirects the output of the ps command to grep, which filters all other processes except hdiutil from ps’s output. Grep’s output then goes to stdout (usually the display, but in this case, do shell script). Other redirection operators are > and >>; one appends output to a file and the other replaces the contents of a file with the output.
Finally, I’m not sure what you were doing wrong, but when I execute,
man sh
I get an sh man page. You may also want to take note of which shell you’re using, because each type has its own man page. “man sh” and “man bash” display the man pages for the GNU Bourne-Again Shell, while “man tcsh” displays the man pages for the C shell. I’m using OS X, 10.4.9, BTW, so if you’re using an older version of the OS, your mileage may vary...but not by much. HTH.
Best,
Dave
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden