From Qt application, starts a java subprocess, and sends a string to it. No need any response from java process.
I want to use QProcess because i think it is more simple than QTcpSocket(not sure).
However, it seems the java subprocess cant recieve the string.
Consider the codes writed below:
Qt Code:
java->setWorkingDirectory("F:/");
java->start("java Test");
if(!java->waitForStarted())
return false;
java->closeWriteChannel();
//qDebug() << qPrintable(str);
std::cout<<qPrintable(str)<<std::endl;
//QTextStream out(stdout);
//out<<str;
QProcess *java= new QProcess();
java->setWorkingDirectory("F:/");
java->start("java Test");
if(!java->waitForStarted())
return false;
java->closeWriteChannel();
QString str = "Test String";
//qDebug() << qPrintable(str);
std::cout<<qPrintable(str)<<std::endl;
//QTextStream out(stdout);
//out<<str;
To copy to clipboard, switch view to plain text mode
Java Code:
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String str;
try {
str = reader.readLine(); }
catch (IOException exc) {
System.out.println("Can't read from stdin!");
return ; }
if(str != null)
System.out.println(str);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String str;
try {
str = reader.readLine(); }
catch (IOException exc) {
System.out.println("Can't read from stdin!");
return ; }
if(str != null)
System.out.println(str);
To copy to clipboard, switch view to plain text mode
How can i get it work as expected? Any advice will be thankful!
Bookmarks