lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 23.03.2010 08:53, Michal Kolodziejczyk wrote:
> On 23.03.2010 08:44, Valerio Schiavoni wrote:
>> hello,
>> i execute a command-line program via popen. This command can receive
>> input from stdin or from a file.
>> The input parameter in my case is a string. Currently, I wrote the
>> string on a temp file, and I specify the name
>> of the file as a parameter to the command given to popen.
>>
>> Do you know if it's possible to play with stdin so that the string is
>> set as the current stdin, so that I avoid to write on disk ?
> 
> Just use pipes:
> 
> $ echo "Long string"|lua -e 'print("String:", io.read("*a"))'

Oh, sorry, I did not read it carefully ;(

In case you want to call a program from within lua:
cmd='echo "Long string"| tr on ON'
fp=io.popen(cmd, 'r')
result=fp:read('*a')
fp:close()
print("Result:",result)

I suppose this should work in windows, too (or maybe you should append
command.com? I have no experience with windows).

Regards,
miko