Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Am I using Process correctly?

Moderators: larsivi kris

Posted: 10/31/07 15:29:59

So I do something like this (on Windows):

import tango.sys.Process;

..

Process p = new Process("pause");
p.execute();

But it fails saying that it can't find "pause". In fact I can't get it to execute anything, ever. I've tried messing with the workDir property but that didn't work.

Is it just b0rken?

I don't know why I'd make a new scripting language. I mean, I might as well just draw some lines in the sand with a stick.

Author Message

Posted: 10/31/07 17:19:38

do you mean "cmd pause" ?

Posted: 10/31/07 17:32:32

I have not had a problem with Process.

I think part of the problem might be that you are trying to execute a command builtin to the cmd shell.

Try this:

import tango.sys.Process;

..

Process p = new Process("cmd", "/c", "pause");
p.execute();

Also, you may note that Process redirects the stdout, stderr, and stdin to pipes stored in the Process object. So if you expect to see "Press any key to continue" you will not unless you pipe the message back to stdout. You also will not be able to end the "pause" without writing a character to the process' stdin. i.e.:

import tango.sys.Process;
import tango.io.Console;

void main()
{
  Process p = new Process("cmd", "/c", "pause");
  p.execute();
  p.stdin.write("any key");
  Cout.stream.copy(p.stdout);
  Cout.stream.flush;
}

BTW, it would be nice to allow executing a process WITHOUT redirecting stdout/stderr/stdin. I will request that in a ticket.

-Steve

Posted: 11/01/07 00:00:12

OK. That works.

I don't know why I'd make a new scripting language. I mean, I might as well just draw some lines in the sand with a stick.

Posted: 11/01/07 00:21:51 -- Modified: 11/01/07 00:22:09 by
kris

BTW: the I/O is mostly chained, so you can do things like:

Cout.stream.copy(p.stdout).flush;