Page 1 of 1

Batch file processing

Posted: Sat Apr 16, 2016 3:38 pm
by lohill
I have a program that takes an input file and re-formats it to an output file in the same directory. I would like to be able to run it as part of a batch processing system where i can have a command line step that looks like: Formatter <inputfile> <outputfile>. I assume that must be possible but need some help getting started. Any ideas or examples would be appreciated.

Thanks,
Larry

Re: Batch file processing

Posted: Sat Apr 16, 2016 6:04 pm
by Klaus
Hi Larry,

hm, does a "simple" repeat loop not work for this?


Best

Klaus

Re: Batch file processing

Posted: Sat Apr 16, 2016 11:00 pm
by lohill
Hi Klaus,

What I want to be able to do its to type a command into the DOS console (if the is the correct way to say it) that would look like this:
MyReformatApp <pathofInpotFile>,<pathofOutputFile> and my LiveCode application (MyReformatApp.exe) would translate the file from one format to another and then shut itself down. Does that make sense? This program could then be called multiple times from a batch process. The batch process would have the repeat loop facilities.

Larry

Re: Batch file processing

Posted: Sun Apr 17, 2016 1:46 am
by FourthWorld
You can run a LiveCode standalone as a faceless process by calling it with -ui in the command line, e.g.:

path/to/my/livecodeapp.exe -ui someotherparams

...where "someotherparams" are any arguments you want to pass to your app, which can be obtained through the $1, $2, $3, etc. global variables. If you need to know the number of arguments passed to it your can check $#.

Re: Batch file processing

Posted: Sun Apr 17, 2016 10:02 am
by Klaus
AHA!

Sorry, did not understand that you want to control your LC app via SHELL!
Yes, what Richard says :D

Re: Batch file processing

Posted: Mon Apr 18, 2016 5:54 pm
by lohill
Klaus and Richard,

Here are the guts of what I have so far and it seems to work. I am not sure how it will behave in a batch environment however. Should there be some kind of wait command before quitting to give time for the process to complete? Is a message sent back from the console that I can trap to know when to quit?

Code: Select all

on startup
   hide this stack
   put word 1 to -1 of lower($1) into lInput
   if lInput is empty or lInput="-h" or lInput="/?" then
      put "A path for a valid input file is required. Path for output file is optional." into tHelp
      write tHelp to stdOut
      quit
   end if
   put word 1 to -1 of lower($2) into lOutput
   if lOutput is empty then
      set the itemdelimiter to slash
      put the last item of lInput into tFile
      put item 1 to -2 of lInput into lOutPut
      put slash & "Out_" & tFile after lOutput
   end if
   put formatFile(lInput) into tResult
   put tResult into URL ("File:" & lOutput)
   quit
end startup
Thanks for any ideas,
Larry

Re: Batch file processing

Posted: Tue Apr 19, 2016 4:14 am
by lohill
Can my LiveCode program be made to have the ability to stop the batch processing until my program has completed the file conversion and quit?

Larry

Re: Batch file processing

Posted: Thu May 19, 2016 4:07 pm
by MaxV
See http://livecode.wikia.com/wiki/Shell
The current handler pauses until the shell returns its result. If the command was successful but did not return anything, the shell function returns empty.
shell() function stop livecode until the command is executed.
Then you can use

Code: Select all

close this stack