Crash when using writeStdin()

Zenith Lau zenithlau at sniic.com
Tue Apr 23 16:05:06 BST 2002


I want to write a kde program to communicate with a shellscript, and I use 
KProcess to run the shellscript. However, the program always crashes when it 
try to write to stdout. How can I solve this problem?


********************************************************
writer.cpp
********************************************************
Writer::Writer(){
	proc = new KProcess();
	*proc<<"/root/test";
	connect(proc, SIGNAL(receivedStdout(KProcess*, char*, int)),
  	 	 this, SLOT(recv(KProcess*, char*, int)));
	connect(proc, SIGNAL(wroteStdin(KProcess*)), this, 		      
		 SLOT(closeSlot(KProcess*)));
	proc->start(KProcess::Block, (KProcess::Communication)(KProcess::Stdin |
            KProcess::Stdout));
}

void Writer::recv(KProcess *p, char *buffer, int buflen){
	output = QString(buffer);
	if (output.find("hello")!=-1)
		sendoutput("abc");
	if (output.find("hi")!=-1)
		sendoutput("123");
}

void Writer::closeSlot(KProcess* p){
	proc->closeStdin();
}

void Writer::sendoutput(const char *s){	
	proc->writeStdin(s, strlen(s));
}

********************************************************
root/test
********************************************************
#!/bin/sh
echo "hello"
read a
echo $a > /root/result
echo "hi"
read b
echo $b >> /root/result

Thx!
Byron
___________________________________________________
This message is from the kde mailing list.
Account management:  http://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.




More information about the kde mailing list