_popen alternative in D?

Vladimir Panteleev vladimir at thecybershadow.net
Thu Jul 21 15:39:31 PDT 2011


On Thu, 21 Jul 2011 18:47:03 +0300, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:

> On Thu, 21 Jul 2011 09:33:34 -0400, Vladimir Panteleev  
> <vladimir at thecybershadow.net> wrote:
>
>> On Thu, 21 Jul 2011 16:19:12 +0300, Maraco <darkandan at windowslive.com>  
>> wrote:
>>
>>> Hello.
>>>
>>> I have a specific problem. I need to redirect console output from a
>>> console program to dfl textbox but i cant find function to do it.
>>> std.process.system only shows exiting code. I think
>>> std.process.shell should do it but it is crashing whole program.
>>>
>>> If You don't know what im asking for there's code how i've done it
>>> in C#:
>>>
>>> *CODE BEGINS
>>> Process p = new Process();
>>>             p.StartInfo.FileName = "shutdown";
>>>             p.StartInfo.Arguments = " /?";
>>>             p.StartInfo.UseShellExecute = false;
>>>             p.StartInfo.RedirectStandardOutput = true;
>>>             p.StartInfo.CreateNoWindow = true;
>>>             p.Start();
>>>
>>>             string output = p.StandardOutput.ReadToEnd();
>>>
>>>             textBox3.Text = output;
>>> *CODE ENDS
>>>
>>> Can you provide me an idea what im doing wrong or alternative to
>>> popen in D langauge?
>>>
>>> Regards.
>>
>> This functionality is currently not implemented in D's standard library.
>> Lars Kyllingstad implemented this in his version of std.process, but  
>> only supporting the POSIX API.
>> For Windows, you'll need to do it manually, in the same way as in C:
>> http://msdn.microsoft.com/en-us/library/ms682499(v=vs.85).aspx
>
> In fact, my windows changes are merged into Lars' branch  
> (https://github.com/kyllingstad/phobos/tree/new-std-process)
>
> *BUT*  (and this is a big but), dmc's runtime incorrectly handles pipes  
> with C's stdio (i.e. FILE *).  Since everything in D right now is FILE *  
> based, it means you can't use pipes at all.
>
> However, I have submitted a patch for DMC's runtime to Walter.   
> Hopefully it will be approved in the near future, and then we can work  
> on merging the new std.process into phobos.

I didn't know it was possible to wrap a Windows pipe in a FILE. Neither  
did I know that the source to DMC's runtime is available.

Would it be possible to fix the ridiculously low open FILE limit on  
Windows as well?

-- 
Best regards,
  Vladimir                            mailto:vladimir at thecybershadow.net


More information about the Digitalmars-d mailing list