• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Is it possible to multi-thread do shell script?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is it possible to multi-thread do shell script?


  • Subject: Is it possible to multi-thread do shell script?
  • From: Patrik <email@hidden>
  • Date: Mon, 07 Dec 2009 19:39:05 -0800

Patrik,

Did you try putting each do shell script statement in an ignoring applications block? As long as you don't need the results from the do shell script command that should cause them each to run concurrently. Each in it's own process.

Paul
-----------

Hi Paul,

Thanks for the tip on "ignore application responses" - I did not get to test this with pdftk but tried it with another shell app I was working with at the moment called pdfmeld which did not work multi-threaded. I will try pdftk later on.

ignoring application responses
do shell script "path/pdfmeld1 input1.pdf,input2.pdf output.pdf -overlay -repeat -force quit"
do shell script "path/pdfmeld2 input2.pdf,input2.pdf output2.pdf -overlay -repeat -force quit"
end ignoring


The first action basically finishes before the 2nd starts. So this does not seem to work for this app at least. Is this a do shell script app limitation? Per the documentation I read the "ignoring responses" clause should handle this.

Best, Patrik

------------------

Hi Axel,

Thanks for your help. I am not too familiar with shell scripting - so I am not sure what "&>/tmp/pdftk.log &" does. As I had to combine pdfs. I did the tests with another command line tool called pdfmeld today which I wanted to also multi-thread.

Does "&" at the end of a statement not do the trick of detaching the process?

In my test I tried the following:

....
repeat with i in mypdfs
do shell script "path/pdfmeld " & i & ",input2.pdf " & i & "_combined.pdf -overlay -repeat -force quit &"
-- the last "&" being the command to detach
end


and I tried

repeat with i in mypdfs
do shell script "path/pdfmeld " & i & ",input2.pdf " & i & "_combined.pdf -overlay -repeat -force &"
end


Both worked but executed lineally instead of at the same time. Also just one core maxes out instead of many. Then just when the last one finishes saving the other kicks in. Each do shell script statement takes about 2.5 minutes so I would definitely see if it kicks in earlier also in the event log.

Pdfmeld also has a "-batch" option which I will check into but I don't think it multi-threads either. Will check if this makes a difference in pdftk. But it seems like this is a shell bug or applescript?

I was hoping that there is a way of telling at least 5 different copies of pdfmeld to run but even with the "ignore application responses" approach applescript seems to be waiting for the last action to finish before starting a new one.

Another option is to just make 5 applets and then execute each manully - thereby manually multi-threading which does work and does use one core per instance so when running it 5 copies of the applet I get 5 cores being used - unless there is another method? Any clues? Was my syntax above right for the "&" usage?

Best, Patrik


Hello Patrick,

You need to fully detach the process. On the other hand, the behavior of the command itself may render it more or less compatible with a background execution.

Could you first try with variations around something like this on the command line
	/path/to/pdftk arg1 arg2 ... argN &>/tmp/pdftk.log &
and see whether you can achieve a successful background execution, ending with a valid pdf file and no errors reported in pdftk.log?

HTH,
Axel



_______________________________________________ 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/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: Is it possible to multi-thread do shell script?
      • From: Axel Luttgens <email@hidden>
  • Prev by Date: RE: Zip and keep folder structure
  • Next by Date: Re: Zip and keep folder structure
  • Previous by thread: Re: Is it possible to multi-thread do shell script?
  • Next by thread: Re: Is it possible to multi-thread do shell script?
  • Index(es):
    • Date
    • Thread