Java Command Line Executor

I have a little problem with running the command line tool. I want to execute UnRAR.exe from WinRAR. I do it like this:

Process process = runtime.exec("\"" + unrarPath + "\"" + " x -kb -vp " + "\"" + fileName + "\"", null, f.getParentFile());

My problem is that the compressed file is password protected. If I execute the command in the console, I will be asked to enter a password. If I let Java execute it, the program simply ends and never waits for user input (password).

I tried to write to the process output, but it did not work. Is there anything I need to know about the behavior of command-line programs running in "different" environments?

EDIT: Perhaps I was not clear enough. My question is: is it possible to interact with the command line program with Java?

+5
source share
2

. , ?

Process tr = Runtime.getRuntime().exec( new String[]{ "cat" } );
Writer wr = new OutputStreamWriter( tr.getOutputStream() );
BufferedReader rd = new BufferedReader( new InputStreamReader( tr.getInputStream() ) );
wr.write( "hello, world\n" );
wr.flush();
String s = rd.readLine();
System.out.println( s );

http://ideone.com/OUGYv

+1 , java.lang.Process , !

+10

.

java Process. 3 (, java-).

java-:

, java:

( "" .exec() ).

, .

Java

0

All Articles