Batch file processing

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Batch file processing

Post by lohill » Sat Apr 16, 2016 3:38 pm

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

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Batch file processing

Post by Klaus » Sat Apr 16, 2016 6:04 pm

Hi Larry,

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


Best

Klaus

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Batch file processing

Post by lohill » Sat Apr 16, 2016 11:00 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Batch file processing

Post by FourthWorld » Sun Apr 17, 2016 1:46 am

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 $#.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Batch file processing

Post by Klaus » Sun Apr 17, 2016 10:02 am

AHA!

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

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Batch file processing

Post by lohill » Mon Apr 18, 2016 5:54 pm

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

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Batch file processing

Post by lohill » Tue Apr 19, 2016 4:14 am

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

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Batch file processing

Post by MaxV » Thu May 19, 2016 4:07 pm

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
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply