Jump to page: 1 2 3
Thread overview
Calling external programs from D
Apr 05, 2006
Tydr Schnubbis
Apr 05, 2006
kris
Apr 05, 2006
Regan Heath
Apr 05, 2006
Tydr Schnubbis
Apr 05, 2006
Tydr Schnubbis
Apr 05, 2006
Regan Heath
Apr 06, 2006
Stuart Delaney
Apr 06, 2006
Regan Heath
Apr 06, 2006
Tydr Schnubbis
Apr 19, 2006
Tydr Schnubbis
Apr 19, 2006
Regan Heath
Apr 19, 2006
Tydr Schnubbis
Apr 19, 2006
Regan Heath
Apr 19, 2006
Tydr Schnubbis
Apr 19, 2006
Regan Heath
Apr 11, 2006
Lionello Lunesu
Apr 11, 2006
BCS
Apr 12, 2006
Lionello Lunesu
Apr 11, 2006
pragma
Apr 12, 2006
Lionello Lunesu
Apr 12, 2006
Kyle Furlong
April 05, 2006
I'm making a gui app with DWT, and I need a way to run an external, command line tool and get its output.  Either directly from the tool's stdout, or by having it write to a file first.

I'm working on windows.  The system() function is unusable because it opens a new command line window when it starts the tool.  That you can get it to close the window again really fast by using 'start' is not good enough

It doesn't have to be a portable way.  If someone can tell me how to call _popen or something in msvcrt.dll, I would be happy.
April 05, 2006
Tydr Schnubbis wrote:
> I'm making a gui app with DWT, and I need a way to run an external, command line tool and get its output.  Either directly from the tool's stdout, or by having it write to a file first.
> 
> I'm working on windows.  The system() function is unusable because it opens a new command line window when it starts the tool.  That you can get it to close the window again really fast by using 'start' is not good enough
> 
> It doesn't have to be a portable way.  If someone can tell me how to call _popen or something in msvcrt.dll, I would be happy.

I understand Regan posted a module to do exactly what you want. Maybe he'll see this, or you may be able to dig it up again from the archives (or via google upon the digitalmars site). Reckon the keywords would be  something like ~ win32 pipe process regan
April 05, 2006
On Wed, 05 Apr 2006 00:36:45 -0700, kris <foo@bar.com> wrote:
> Tydr Schnubbis wrote:
>> I'm making a gui app with DWT, and I need a way to run an external,
>> command line tool and get its output.  Either directly from the tool's
>> stdout, or by having it write to a file first.
>>  I'm working on windows.  The system() function is unusable because it
>> opens a new command line window when it starts the tool.  That you can
>> get it to close the window again really fast by using 'start' is not
>> good enough
>>  It doesn't have to be a portable way.  If someone can tell me how to
>> call _popen or something in msvcrt.dll, I would be happy.
>
> I understand Regan posted a module to do exactly what you want. Maybe
> he'll see this, or you may be able to dig it up again from the archives
> (or via google upon the digitalmars site). Reckon the keywords would be
>   something like ~ win32 pipe process regan

Here they/it is :)
Regan

April 05, 2006
Regan Heath wrote:
> On Wed, 05 Apr 2006 00:36:45 -0700, kris <foo@bar.com> wrote:
>> Tydr Schnubbis wrote:
>>> I'm making a gui app with DWT, and I need a way to run an external,  command line tool and get its output.  Either directly from the tool's  stdout, or by having it write to a file first.
>>>  I'm working on windows.  The system() function is unusable because it  opens a new command line window when it starts the tool.  That you can  get it to close the window again really fast by using 'start' is not  good enough
>>>  It doesn't have to be a portable way.  If someone can tell me how to  call _popen or something in msvcrt.dll, I would be happy.
>>
>> I understand Regan posted a module to do exactly what you want. Maybe  he'll see this, or you may be able to dig it up again from the archives  (or via google upon the digitalmars site). Reckon the keywords would be    something like ~ win32 pipe process regan
> 
> Here they/it is :)
> Regan

Thanks!

But it doesn't work for me.  Seems that it blocks the new process from acessing the network.  Any ideas what to do?
April 05, 2006
Tydr Schnubbis wrote:
> Regan Heath wrote:
>> On Wed, 05 Apr 2006 00:36:45 -0700, kris <foo@bar.com> wrote:
>>> Tydr Schnubbis wrote:
>>>> I'm making a gui app with DWT, and I need a way to run an external,  command line tool and get its output.  Either directly from the tool's  stdout, or by having it write to a file first.
>>>>  I'm working on windows.  The system() function is unusable because it  opens a new command line window when it starts the tool.  That you can  get it to close the window again really fast by using 'start' is not  good enough
>>>>  It doesn't have to be a portable way.  If someone can tell me how to  call _popen or something in msvcrt.dll, I would be happy.
>>>
>>> I understand Regan posted a module to do exactly what you want. Maybe  he'll see this, or you may be able to dig it up again from the archives  (or via google upon the digitalmars site). Reckon the keywords would be    something like ~ win32 pipe process regan
>> 
>> Here they/it is :)
>> Regan
> 
> Thanks!
> 
> But it doesn't work for me.  Seems that it blocks the new process from acessing the network.  Any ideas what to do?

Here's a minimal test to show the problem:

import lib.process;
import std.stdio;

void main()
{
	Process proc;
	proc = new Process("ping google.com");
	writef(proc.readLine());
}

Compile: "dmd test.d lib/process.d lib/pipestream.d"

Output: "Ping request could not find host google.com. Please check the name and try again."

;)
April 05, 2006
On Wed, 05 Apr 2006 19:22:25 +0200, Tydr Schnubbis <fake@address.dude> wrote:
>>> On Wed, 05 Apr 2006 00:36:45 -0700, kris <foo@bar.com> wrote:
>>>> Tydr Schnubbis wrote:
>>>>> I'm making a gui app with DWT, and I need a way to run an external,  command line tool and get its output.  Either directly from the tool's  stdout, or by having it write to a file first.
>>>>>  I'm working on windows.  The system() function is unusable because it  opens a new command line window when it starts the tool.  That you can  get it to close the window again really fast by using 'start' is not  good enough
>>>>>  It doesn't have to be a portable way.  If someone can tell me how to  call _popen or something in msvcrt.dll, I would be happy.
>>>>
>>>> I understand Regan posted a module to do exactly what you want. Maybe  he'll see this, or you may be able to dig it up again from the archives  (or via google upon the digitalmars site). Reckon the keywords would be    something like ~ win32 pipe process regan
>>>  Here they/it is :)
>>> Regan
>>  Thanks!
>>  But it doesn't work for me.  Seems that it blocks the new process from acessing the network.  Any ideas what to do?
>
> Here's a minimal test to show the problem:
>
> import lib.process;
> import std.stdio;
>
> void main()
> {
> 	Process proc;
> 	proc = new Process("ping google.com");
> 	writef(proc.readLine());
> }
>
> Compile: "dmd test.d lib/process.d lib/pipestream.d"

> Output: "Ping request could not find host google.com. Please check the name and try again."

(Cross posted to digitalmars.D so more people see it)

(You have to move the readLine function from private to public in pipestream, that was obviously a mistake on my part)

I get the same result. Odd. I thought at first it might be because ping uses enviroment variables to find/use the DNS service, but adding the current enviroment variables to the new process makes no difference:

import lib.process;
import std.stdio;
import std.string;
import std.c.string;

extern(C) extern char **_environ;

void main()
{
	Process proc;
	proc = new Process();
	for(int i = 0; _environ[i]; i++) {
		proc.addEnv(toString(_environ[i]).dup);
	}
	proc.execute("ping www.google.com");
	writef(proc.readLine());
}

I also tried using CreateProcessAsUser with the handle returned by:
  OpenProcessToken(GetCurrentProcess(), ..etc..

it made no difference (not that I expected it to, but you never know).

Does anyone have any idea why ping cannot access the DNS service?

Regan
April 06, 2006
There's a bug in the makeBlock functions in process.d. The first parameter to calloc should be 1 not 0. With that change (and the private readLine one) it works fine for me.  Don't have an answer to the OP's DNS problem though.

hope this helps. cheers,
Stu

In article <ops7j4wey023k2f5@nrage.netwin.co.nz>, Regan Heath says...
>
>On Wed, 05 Apr 2006 19:22:25 +0200, Tydr Schnubbis <fake@address.dude> wrote:
>>>> On Wed, 05 Apr 2006 00:36:45 -0700, kris <foo@bar.com> wrote:
>>>>> Tydr Schnubbis wrote:
>>>>>> I'm making a gui app with DWT, and I need a way to run an external,
>>>>>> command line tool and get its output.  Either directly from the
>>>>>> tool's  stdout, or by having it write to a file first.
>>>>>>  I'm working on windows.  The system() function is unusable because
>>>>>> it  opens a new command line window when it starts the tool.  That
>>>>>> you can  get it to close the window again really fast by using
>>>>>> 'start' is not  good enough
>>>>>>  It doesn't have to be a portable way.  If someone can tell me how
>>>>>> to  call _popen or something in msvcrt.dll, I would be happy.
>>>>>
>>>>> I understand Regan posted a module to do exactly what you want. Maybe  he'll see this, or you may be able to dig it up again from the archives  (or via google upon the digitalmars site). Reckon the keywords would be    something like ~ win32 pipe process regan
>>>>  Here they/it is :)
>>>> Regan
>>>  Thanks!
>>>  But it doesn't work for me.  Seems that it blocks the new process from
>>> acessing the network.  Any ideas what to do?
>>
>> Here's a minimal test to show the problem:
>>
>> import lib.process;
>> import std.stdio;
>>
>> void main()
>> {
>> 	Process proc;
>> 	proc = new Process("ping google.com");
>> 	writef(proc.readLine());
>> }
>>
>> Compile: "dmd test.d lib/process.d lib/pipestream.d"
>
>> Output: "Ping request could not find host google.com. Please check the name and try again."
>
>(Cross posted to digitalmars.D so more people see it)
>
>(You have to move the readLine function from private to public in pipestream, that was obviously a mistake on my part)
>
>I get the same result. Odd. I thought at first it might be because ping uses enviroment variables to find/use the DNS service, but adding the current enviroment variables to the new process makes no difference:
>
>import lib.process;
>import std.stdio;
>import std.string;
>import std.c.string;
>
>extern(C) extern char **_environ;
>
>void main()
>{
>	Process proc;
>	proc = new Process();
>	for(int i = 0; _environ[i]; i++) {
>		proc.addEnv(toString(_environ[i]).dup);
>	}
>	proc.execute("ping www.google.com");
>	writef(proc.readLine());
>}
>
>I also tried using CreateProcessAsUser with the handle returned by:
>   OpenProcessToken(GetCurrentProcess(), ..etc..
>
>it made no difference (not that I expected it to, but you never know).
>
>Does anyone have any idea why ping cannot access the DNS service?
>
>Regan


April 06, 2006
On Thu, 6 Apr 2006 14:46:09 +0000 (UTC), Stuart Delaney <Stuart_member@pathlink.com> wrote:
> There's a bug in the makeBlock functions in process.d. The first parameter to
> calloc should be 1 not 0. With that change (and the private readLine one) it
> works fine for me.  Don't have an answer to the OP's DNS problem though.

You're dead right. With those changes it works for me too.

Regan
April 06, 2006
Regan Heath wrote:
> On Thu, 6 Apr 2006 14:46:09 +0000 (UTC), Stuart Delaney  <Stuart_member@pathlink.com> wrote:
>> There's a bug in the makeBlock functions in process.d. The first  parameter to
>> calloc should be 1 not 0. With that change (and the private readLine  one) it
>> works fine for me.  Don't have an answer to the OP's DNS problem though.
> 
> You're dead right. With those changes it works for me too.

I've fixed the calloc calls too, but it doesn't help.  If I try to ping google's IP, which is 64.233.167.99 according to ping, I get "Pinging Error: 4invalid UTF-8 sequence".  Maybe my windows installation is screwed, it's getting really old...

Btw, I use dmd 0.148, haven't tried this with any other version yet.
April 11, 2006
Just some idea:

Wouldn't it be nice if there were an "extern (System)" calling convention that would start external programs?

For example:

#extern (System) int wget(...);
#
#int main() {
#  return wget("http://whatever");
#}

This would boost productivity especially for D scripts. Only too often I need a small, temporary program to process some data and I wish I had the compilable source of wget/grep/utility-x at hand to incorporate their functionality.

Seems easy enough to implement using spawning/waiting. The program can be declared with "..." or some defined arugments, but all arguments to the function would have to be cast to char[] for passing to the new process. Would of course be even cooler if the linker could pull in the external program's main(), but I suppose that's a bit tricky :)

L.
« First   ‹ Prev
1 2 3