PDA

View Full Version : How to wait for a shell script command to finish?




iostream.h
Nov 23, 2005, 12:58 PM
I'd like to have a specific shell script complete before a function is called. This command has no specified time limit. All documentation I have found online shows how to pause the script for a certain task to finish within an application, not for a "do shell script" command itself. Secondly, I don't want to freeze up any other processes when this is stalling. Anyone know how to do this?


do shell script "somecommand"
-- Something Here
my function()



kainjow
Nov 23, 2005, 01:27 PM
AFAIK, "do shell script" waits for the script to finish execution.

It will also only block your process, not any other processes.

iostream.h
Nov 23, 2005, 01:29 PM
AFAIK, "do shell script" waits for the script to finish execution.

It will also only block your process, not any other processes.

It doesn't in this case :(

redeye be
Nov 23, 2005, 02:52 PM
Could it be that a script returns a value on completion (like 0 if succeeded, something else when an error occurred). Maybe i'm thinking of functions to much.
You could test it out quite easily.

I could be dead wrong though ;)

nichos
Nov 23, 2005, 03:27 PM
Is your "some command" forking? I think what you want to do is this:



#!/bin/sh
first_action && second_action


the double &'s will make second_action wait for first_action to complete.

iostream.h
Nov 23, 2005, 10:39 PM
The command is "open -a /Applications/iTunes.app ~/Backup/Music/*".

So I guess a more appropriate question is to find out how to determine whether iTunes is busy or not.

iostream.h
Nov 23, 2005, 10:40 PM
The command is "open -a /Applications/iTunes.app ~/Backup/Music/*".

So I guess a more appropriate question is to find out how to determine whether iTunes is busy or not.

On a related note, iTunes does not have "is busy" or anything similar.

kainjow
Nov 23, 2005, 11:34 PM
In your case, "do shell script" waits for the script to end, so it's working how it should. "open" simply launches another process if the path given is a process. So you need to think in different terms....

nichos
Nov 24, 2005, 01:03 AM
Kind of crude, but what about something like:
command1
sleep(length)
command2

I don't know if "sleep" is valid or not, you'd have to man bash, or maybe sleep. What does this command of yours do? Open your backup/music folder in itunes? If so, and I don't know much about how iTunes works, but could you make a symlink from your backup/music to /path/to/itunes/library? I tunes might use some sort of DB, so I don't know if that will work.

Thom_Edwards
Nov 24, 2005, 02:25 AM
have the called script create a file when it completes, then have the calling code go into a while loop that doesn't break until it finds the file. don't forget to delete the file after breaking out of the loop, though! this should work if i'm understanding your problem correctly.