September 05, 2010, 08:20:16 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: do shell script 'nohup'  (Read 37 times)
0 Members and 1 Guest are viewing this topic.
cdms
Jr. Member
**

Karma: 6
Offline Offline

Gender: Male
Posts: 84


« on: July 22, 2010, 07:01:42 AM »

I am trying to run a 'do shell script' using nohup to ensure the process continues running in background after the script finishes.
However, the script never gets past the do shell script line until I go into terminal and kill the started process. It doesn't even time-out.
I have tried putting the nohup lines into a new shell script and then running that. This is slightly worse in that the shell script finishes, having started the required processes but the applescript is again stuck at the do shell script command and now I have now process to kill to 'release' it.

Anybody out there tried doing this and got round this problem?

Logged
Publi-Script
Administrator
Hero Member
*****

Karma: 16
Offline Offline

Gender: Male
Posts: 544


Automate your Life!


WWW
« Reply #1 on: July 23, 2010, 07:17:39 AM »

I have never seen that "nohup" parameter... Where did you get this from?

Logged

Michel Lemieux
Forum Administrator
-------------------------
OS X 10.5.8
Quark 6.5 / 7.5 / 8.01
Illustrator CS / CS2 / CS3 / CS4
Photoshop CS / CS2 / CS3 / CS4
InDesign CS / CS2 / CS3 / CS4
Dreamweaver 8 / 9 / CS4
Script Debugger 3
Publi-Script
Administrator
Hero Member
*****

Karma: 16
Offline Offline

Gender: Male
Posts: 544


Automate your Life!


WWW
« Reply #2 on: July 23, 2010, 08:47:35 AM »

Oh, I get it, "nohup" is a shell command...

This worked of my machine:
Quote
001     set ScriptB to ""
002     set ScriptB to ScriptB & "say \"Hello there!\""

003     set ScriptA to ""
004     set ScriptA to ScriptA & "nohup " & ScriptB

005     set ScriptResults to do shell script ScriptA
Notes:
• The line numbers included with this script are there to aid future discussions. In order to use this script, you will have to strip them all from the code.


HTH


Logged

Michel Lemieux
Forum Administrator
-------------------------
OS X 10.5.8
Quark 6.5 / 7.5 / 8.01
Illustrator CS / CS2 / CS3 / CS4
Photoshop CS / CS2 / CS3 / CS4
InDesign CS / CS2 / CS3 / CS4
Dreamweaver 8 / 9 / CS4
Script Debugger 3
cdms
Jr. Member
**

Karma: 6
Offline Offline

Gender: Male
Posts: 84


« Reply #3 on: July 23, 2010, 09:20:57 AM »

After some digging and messing with redirection of output I have achieved what I want.
The point of the nohup is to stop a background process being killed when it's parent process ends.
If you open a terminal window and issue the command

/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &

You will have your current screen saver as your wallpaper. Kind of neat but an aside at this point.
If you close the terminal window it closes the ScreenSaverEngine process.
Now if you open a new terminal window and issue the same command prefixed with 'nohup ' you can close the terminal window and the screen saver process stays alive. You will have to open another terminal, find the process and kill it manually.

Your script works because the say command finishes. If you 'do shell script' for the above command the applescript will get hung up waiting for a response which doesn't come because the process is persistent. You have to kill the started process to release the script. (Still not sure why it doesn't time out.)

What you have to do is redirect all the output so the applescript knows not to wait for any return. I had tried a number of different redirects when somebody told me to try &> /dev/null.
So the whole command becomes

do shell script "nohup /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &> /dev/null &"

now the applescript knows to continue, can be closed and the process continues to run in background.

Thanks anyway.

P.S. This wasn't all just so I can have moving wallpaper but that served nicely as a fun example

Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!