netbeans - Issue with a Process Object of Java -
i have problem process object of java.
i want open process called linphonec.exe make calls, , inside process have insert few command lines calls, answer ...
the problem comes when have insert more 1 command line because outputstream of process accepts command line when call close() method of outputstream. if dont call method command line isn't executed.
i want execute more 1 command can't.
example:
"call phone" , "terminate" end call whenever want.
but can insert first command line , if dont use close() method command line not executed.
code:
start process:
processbuilder builder = new processbuilder(process); builder.redirecterrorstream(true); process p = builder.start(); read inputstream of process:
inputstream = p.getinputstream(); system.out.print((char)i.read()); while(i.available() > 0){ system.out.print((char)i.read()); } insert command line outputstream:
string command = com.nextline(); outputstream o = p.getoutputstream(); o.write(comando.getbytes()); o.flush(); o.close(); if delete "o.close()" command line not executed, if execute can't execute other command lines.
i tried code on program, when insert command line dont see next information of process.
when put code :
ready warning: video disabled in linphonec, use -v or -c or -d enable. linphonec> registration on sip:xx.xx.xx.xx successful. linphonec> call xxx exemple code:
ready warning: video disabled in linphonec, use -v or -c or -d enable. linphonec> registration on sip:xx.xx.xx.xx successful. linphonec> call xxx establishing call id sip:xxx@xx.xx.xx.xx, assigned id 1 "available > 0" "establishing call id sip:xxx@xx.xx.xx.xx, assigned id 1". if use loop dont see other info of process.
i think problem outputstream not command lines until execute close method.
thank you.
sorry bad englando.
i suspect problem here:
inputstream = p.getinputstream(); system.out.print((char)i.read()); while(i.available() > 0){ system.out.print((char)i.read()); } if there temporary pause in stream of bytes coming process via input stream, available() return 0 , read loop terminate. game over.
don't use available() ...
here's loop should like:
inputstream = p.getinputstream(); int input; while ((input = i.read()) != -1) { system.out.print((char) input); } why work?
instead of testing see if there bytes read, read anyway. read() call block until either there character read, or "other end" closes pipe. in latter case, read() return -1 indicate end-of-stream has been reached.
update
so that's not problem. (or @ least, not whole problem).
another possibility not writing correct kind of line terminators output stream. cause external process not "complete" command until close stream.
a third possibility need synchronize application; i.e. wait output first command before sending second one, , on.
Comments
Post a Comment