Runtime Prozeß hängt sich auf. in der Kommandozeile gehts

Status
Nicht offen für weitere Antworten.

DLor

Aktives Mitglied
Code:
Runtime runner = Runtime.getRuntime();
			Process proc;

			try
			{
				// try to execute the tool with the given list of parameters 
				proc = runner.exec(commandLine);

				// if the caller wants to wait for the exit of this new process
				if(waitForExit)
				{
					try
					{
						// try to wait for the exit of the process...
						proc.waitFor();

						// write the EEx-Tool state into the Test-Logfile
						if(proc.exitValue() == 0)
						{
							System.out.println("OK");
							exitCode &= true;
						}
						else
						{
							System.out.println("!OK");
							exitCode &= false;
						}
					}
					catch(InterruptedException e)
					{
						// error handling if the created process has been interrupted
						System.out.println("InterruptedException "+e.getMessage());
						exitCode = false;
					}
				}
				else
				{
					// the caller does not want to wait for the child's exit,
					// so we cannot set any exit code for the child process.

					// let's hope that nothing went wrong...
				}
			}
			catch(IOException e)
			{
				// error handling if the creation of the process has failed
				getTestLogger().error("IOException "+e.getStackTrace());
				exitCode = false;
			}

Das ist mein Code.
Nun habe ich das Problem, das ein Aufruf nicht terminiert. Wenn ich jedoch den selbigen Aufruf in der Commandozeile per hand mache terminiert der Aufruf nach kürzester Zeit. zwar mit einer Exception, aber er terminiert.
Wie kann ich herausfinden, wodurch mein Runtime.exec() sich aufhängt?

Vielen Dank
DLor
 
Wenn jemand das gleiche problem mal haben sollte...

Der InputStream und der ErrorStream müssen umgeleitet werden.
Am besten ein Thread laufen lassen, der beide z.B. auf der console ausgeben.

Das Problem war, das 1kb der ausgabe im stream liegen alles was darüber geht wird gebuffert. solange der Buffer nicht leer ist, kommt der prozeß leider nicht zu einem ende.

Mal sehen ob das mal jemand benötigt!!!
 
hehe, servus! danke für den tip. das riecht mir so nach meinem problem. terminiert bei mir auch nicht. ich probiers mal und melde mich nochmal....
 
also, wie machst du das konkret? mein command produziert auf der commandozeile eine menge output während er läuft, das ding erzählt dir so ziemlich alles was es macht (welche directories er angelegt hat usw...). da kommen also schnell mehr als 1kb zusammen. wie nehm ich dem command das nun(während er läuft) ab, sprich wie lass ich es mir auf der java console ausgeben? das raff ich nicht so ganz... ???:L


hier ein auszug aus meinem code:

Code:
try
	        					{
	        						Process p = new Process(command);
	        						
	        						DataInputStream ips = p.getInputStream();
	        						
	        						while(ips.read()!=-1) {} //einfach ins leere damit... ?
	        					}
	        					catch(Exception e)
	        					{
	        						e.printStackTrace();
	        					}


kann mir irgedwer nen kurzen tipp geben?
 
das ging schneller als ich dachte, hier ist die lösung:

Code:
try
	        					{
	        						Process p = Runtime.getRuntime().exec(command);
	        						
	        						InputStream ips = p.getInputStream();                                
	        						
	        						int c;
	        						StringBuilder commands_output = new StringBuilder();
	                                
	        						while( (c=ips.read())!=-1)	                              
	        						commands_output.append((char)c);
	        						
	        						System.out.println(commands_output.toString());
	        						
	        					}
	        					catch(Exception e)
	        					{
	        						e.printStackTrace();
	        					}

den errorstream kann man natürlich auch so abfangen....
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben