How to wait for a shell script command to finish?

Discussion in 'Mac Programming' started by iostream.h, Nov 23, 2005.

  1. macrumors regular

    Joined:
    Mar 4, 2004
    Location:
    Albuquerque, NM
    #1
    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?

    Code:
    do shell script "somecommand"
    -- Something Here
    my function()
    
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    AFAIK, "do shell script" waits for the script to finish execution.

    It will also only block your process, not any other processes.
     
  3. thread starter macrumors regular

    Joined:
    Mar 4, 2004
    Location:
    Albuquerque, NM
    #3
    It doesn't in this case :(
     
  4. macrumors 65816

    redeye be

    Joined:
    Jan 27, 2005
    Location:
    BXL
    #4
    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 ;)
     
  5. macrumors 6502

    nichos

    Joined:
    Jul 17, 2004
    Location:
    Jacksonville, Fl
    #5
    Is your "some command" forking? I think what you want to do is this:

    the double &'s will make second_action wait for first_action to complete.
     
  6. thread starter macrumors regular

    Joined:
    Mar 4, 2004
    Location:
    Albuquerque, NM
    #6
    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.
     
  7. thread starter macrumors regular

    Joined:
    Mar 4, 2004
    Location:
    Albuquerque, NM
    #7
    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.
     
  8. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    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....
     
  9. macrumors 6502

    nichos

    Joined:
    Jul 17, 2004
    Location:
    Jacksonville, Fl
    #9
    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.
     
  10. macrumors regular

    Joined:
    Apr 11, 2003
    #10
    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.
     

Share This Page