PDA

View Full Version : Tip: Pipes and backticks in v1.1.3



barrymavin
2014-05-23, 03:06
In v1.1.3Beta10 I have enabled the pipetostr() function and the use of backticks on all operating systems.

What are backticks and why should i care you may ask?

Let's say for example you have an external exe written in .net and you want to run it specifying some arguments and capture the output so you can integrate existing business logic into your Lianja App.

Its as simple as this.



result = pipetostr("c:\mydir\myprog.exe arg1 arg2 arg3 argn")
// now result contains whatever myprog.exe wrote to standard output so you could use the json_decode()
// or xml_decode() functions to process the result.
//
// If the result is particularly long write out to a temp file name and use json_decode_file() or xml_decode_file()
// respectively


To simplify things and to borrow from the linux bash shell, Lianja supports back ticks too.



? "`dir *.xml`"
// notice how `command....` can be used in any character string ( thats a backwards ` not a ' )

HankFay
2014-05-23, 11:53
Very cool. Thanks!

tekhong
2014-05-23, 18:03
Hi Barry

May I know the differnce between RUN and PIPETOSTR and SHELLEXEC commands?

Your advice is much appreciated

Thanks & Best Regards

lianjasupport
2014-05-23, 20:52
Hi Tek Hong

RUN executes a command line without capturing it's output, waits for command completion
SPAWN executes a command line without capturing it's output. Starts the command and continues execution in parallel
PIPETOSTR() executes a command line capturing and returning whatever it wrote to its standard output, waits for completion.
Bacticks can be used inside character strings to capture the output and substitute into the character string
SHELLEXEC is a windows only and non portable WINAPI function call

Also note that you can execute a program via file association e.g. To open up PDF file.

Lianja.showDocument("myfile.pdf")