www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [D Cookbook]about "Communicating with external processes" part.

reply xky <mozirikan gmail.com> writes:
Hello. :)
I just got a this problem when i read "D Cookbook".



[ pipe.d ]:
======================================================================
import std.process;
import std.stdio;

void main(){
	auto info = pipeProcess("child.exe");
	scope(exit) wait(info.pid);

	info.stdin.writeln("data to send to the process");
	info.stdin.close();

	foreach(line; stdout.byLine){
		writeln("Received ", line, " from child.");
	}
}
======================================================================



[ child.d ]:
======================================================================
import std.stdio;
void main(){
	writeln("hello");
}
======================================================================



[ CMD ]:
======================================================================
C:\Users\user\Desktop\pipe>pipe.exe
std.stdio.StdioException std\stdio.d(3867
----------------
0x00407BEF
0x00403149
0x004029F0
0x0040289B
0x0040307F
0x00403032
0x0040300E
0x00402FC1
0x0040272F
0x004026DB
0x004020E2
0x00406412
0x004063E7
0x004062FB
0x00403E7F
0x7493336A in BaseThreadInitThunk
0x76EF9882 in RtlInitializeExceptionChain
0x76EF9855 in RtlInitializeExceptionChain
Failed to flush stdout: No error
======================================================================



Well... That's all! It's my mistake? How can i slove this 
problem? :/

regards,
Sep 13 2015
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
I'm in a super rush, running late to something else, but try 
using readln in the child before writing and see what happens. 
You sent data to it but the child never read it.
Sep 13 2015
parent xky <mozirikan gmail.com> writes:
On Sunday, 13 September 2015 at 13:34:18 UTC, Adam D. Ruppe wrote:
 I'm in a super rush, running late to something else, but try 
 using readln in the child before writing and see what happens. 
 You sent data to it but the child never read it.
oh my... you're right. lol so, i fix "pipe.d" this: [ pipe.d ] ============================================================ import std.process; import std.stdio; void main(){ auto info = pipeProcess("child.exe"); scope(exit) wait(info.pid); //info.stdin.writeln("data to send to the process"); foreach(line; info.stdout.byLine){ writeln("Result:", line); } } ============================================================ [ CMD ] ============================================================ C:\Users\user\Desktop\pipe>pipe Result:hello ============================================================ work fine. thx so much. :)
Sep 13 2015
prev sibling parent reply anonymous <anonymous example.com> writes:
On Sunday 13 September 2015 15:32, xky wrote:

 [ pipe.d ]:
 ======================================================================
 import std.process;
 import std.stdio;
 
 void main(){
 	auto info = pipeProcess("child.exe");
 	scope(exit) wait(info.pid);
 
 	info.stdin.writeln("data to send to the process");
 	info.stdin.close();
 
 	foreach(line; stdout.byLine){
I think it should be `info.stdout.byLine` here.
 		writeln("Received ", line, " from child.");
 	}
 }
 ======================================================================
Sep 13 2015
parent xky <mozirikan gmail.com> writes:
On Sunday, 13 September 2015 at 13:44:06 UTC, anonymous wrote:
 On Sunday 13 September 2015 15:32, xky wrote:

 [ pipe.d ]:
 ======================================================================
 import std.process;
 import std.stdio;
 
 void main(){
 	auto info = pipeProcess("child.exe");
 	scope(exit) wait(info.pid);
 
 	info.stdin.writeln("data to send to the process");
 	info.stdin.close();
 
 	foreach(line; stdout.byLine){
I think it should be `info.stdout.byLine` here.
 		writeln("Received ", line, " from child.");
 	}
 }
 ======================================================================
Yes, thanks for the tip detail!
Sep 13 2015