to get process id

Regan Heath regan at netwin.co.nz
Fri May 26 05:41:36 PDT 2006


On Fri, 26 May 2006 10:19:32 +0000 (UTC), nobody  
<nobody_member at pathlink.com> wrote:
> Hello,
>
> i have successfully compile my program, but i get no
> response.
>
>
> import lib.process;
> import lib.pipestream;
> import std.stdio;
> import std.string;
>
> void main()
> {
> auto Process p = new Process("ls -la");

The problem is that "ls" does not exist in the current directory. You need  
to include the full path to the binary, eg.
   auto Process p = new Process("/bin/ls -la");

fork/execve doesn't work like the bash shell, it won't scan the PATH for  
the command it's given, it just runs exactly what you ask it to.

I need to look into what I can do in the event of a failure to notify the  
parent thread (cos once you call fork() you get a copy, that copy calls  
execve and should never return, it does, indicating a failure).

> writefln("%s",p.readLine());
> }
> // dmd ping.d lib/process.d lib/pipestream.d
>> build ping
> gcc lib/process.o ping.o lib/pipestream.o -o ping -m32 -lphobos  
> -lpthread -lm
>
>
> I have comment in the line 230 in process.d
> extern (C) char* strerror(int);
> and the line 50 in pipestream.d
> char* strerror(int);

Yep, those are declared in std.string and we don't need to declare them  
anymore.

Regan



More information about the Digitalmars-d-learn mailing list