Making a call to the command line/shell and receiving string back

46 views
Skip to first unread message

PaulANormanNZ

unread,
Oct 5, 2011, 6:48:19 PM10/5/11
to GLUEscript
HI,

I'm still working through the documentation, is this where GLUEscript
can make a system call as it were to the command-line to launch
external processes and receive results back - system.Process and
various system.Pipe ?

So that would look something like ...?

system = require("system");

var cmdErr = new system.Pipe();
var cmdOut = new system.Pipe();
var cmdIn= new system.Pipe();

// something trivial
var getInfo = new system.Process("dir", ["/b", "/ad", "*.jpg"], cmdIn,
cmdOut, cmdErr );

getInfo.wait();

// and then then cmdErr can be tested for error messages, and cmdIn
read as a string?

Paul

PaulANormanNZ

unread,
Oct 6, 2011, 6:02:55 AM10/6/11
to GLUEscript
I've looked through http://www.appinf.com/docs/poco/Poco.Process.html
Could not find much there to point me in the right directoin just when
they get to the good stuff they write...

PipeInputStream istr(outPipe);
... // read output of ps from istr
int rc = ph.wait();

Any way this is what I tried, and not surprisingly it crashes!

system = require("system");

var cmdErr = new system.Pipe();
var cmdOut = new system.Pipe();
var cmdIn= new system.Pipe();

// something trivial
var getInfo = new system.Process("cmd", ["/c", "dir", "/b", "/ad", "G:
\\hold"], cmdIn,
cmdOut, cmdErr );

getInfo.wait();

print("\nDir out put length plus text follows: \n\n");
var xx;
var text ="";
// var find = 0;

var inputStream = new system.PipeInputStream(cmdOut);

inputStream.seek(system.InputStream.SEEK_BEG);


while (inputStream.eof != true)
{
print(inputStream.pos);

hold = inputStream.read(1);
text += hold.decodeToString();
print("ok");
lookAhead = inputStream.peek();

if (lookAhead == inputStream.eof)
{
break;
}

}

print(inputStream.pos + "\n");

print(text);

But I am afraid I am on the wrong track

Paul A Norman

unread,
Oct 6, 2011, 6:05:27 AM10/6/11
to GLUEscript
P.S. this immeadiatley sends my process output to the command line with out allowing me to store it in a variable for processing, then after my first  print(inputStream.pos); in the while  loop crashes.

--
You received this message because you are subscribed to the Google Groups "GLUEscript" group.
To post to this group, send email to glues...@googlegroups.com.
To unsubscribe from this group, send email to gluescript+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gluescript?hl=en.


Franky Braem

unread,
Oct 7, 2011, 5:30:02 AM10/7/11
to glues...@googlegroups.com
I've found some problems in launching the process: the pipes were not passed to the launch method. This doesn't solve everything. Looking further ...

Op 6/10/2011 12:05, Paul A Norman schreef:

Paul A Norman

unread,
Oct 7, 2011, 7:29:08 AM10/7/11
to glues...@googlegroups.com
Many thanks Franky,

I had no idea what was happening or what I should be doing :)

Was my last code headed in the right direction if everything was working?

Paul

Franky Braem

unread,
Oct 7, 2011, 8:52:30 AM10/7/11
to glues...@googlegroups.com
You must call wait() after processing all the output. But at the moment I still have crashes when reading from stdout.

Franky

Op 7/10/2011 13:29, Paul A Norman schreef:

Paul A Norman

unread,
Oct 7, 2011, 6:21:18 PM10/7/11
to glues...@googlegroups.com
Thanks,

Earlier on from the Poco web site I had seen wait() called at the end, and tried that and got crashes  too, so moved it up experimentally.

Paul
Reply all
Reply to author
Forward
0 new messages