aspose file tools*
The moose likes Java in General and the fly likes Another Runtime Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Another Runtime Problem" Watch "Another Runtime Problem" New topic
Author

Another Runtime Problem

Tom Hill
Ranch Hand

Joined: Aug 24, 2003
Posts: 115


Am I missing something, the commands in the array dont appear to get processed at all
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
This is just a guess at what might be wrong; I haven't tried it. I'm thinking it may be that Windows doesn't like the "\n" on the end of your command string. Newline in Windows is "\r\n".

To fix, either just try that as the rest of your code is tied to Windows anyway or, in the interest of portability , use bw.newLine() or swap your BufferedWriter for a PrintWriter and use println().

Jules
Tom Hill
Ranch Hand

Joined: Aug 24, 2003
Posts: 115
Bizzare - none of those worked Does this happen in Unix too? I've got this working before now and it seems to have magically stopped!!

Tom
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Doesn't "cmd /c somecommand" tell cmd.exe to execute "somecommand" and then exit? Maybe you want to save "dir c:\\software" for the "commands" array.


[Jess in Action][AskingGoodQuestions]
Tom Hill
Ranch Hand

Joined: Aug 24, 2003
Posts: 115
okay it does appear to run a command and the exit, hence why it stops early - but what should be there then?
Tom Hill
Ranch Hand

Joined: Aug 24, 2003
Posts: 115
hmm ive just tried it on a linux machine and im getting the same problems
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12836
    
    5
1. If you don't flush the bw stream, the commands may still be in the buffer.
2. You really need to set up a separate Thread to read the output - if the process output doesn't get consumed, it may just sit there.
Bill
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by Tom Hill:
okay it does appear to run a command and the exit, hence why it stops early - but what should be there then?


Just "cmd.exe".

Regarding doing something similar on Unix -- if you mean running sh -c "some command" and then trying to send more commands: yep, same problem, same reason.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
side note: why aren't you using Java to perform what you are attempting?

Your system commands look like a broken approach.


Tony Morris
Java Q&A (FAQ, Trivia)
Tom Hill
Ranch Hand

Joined: Aug 24, 2003
Posts: 115
because I wanted to start with easy commnads I know the results of rather than the actuall commands that will be run
Tom Hill
Ranch Hand

Joined: Aug 24, 2003
Posts: 115
Interesting : on windows /k is required to keep the shell open to write commands too. In unix the first command has to be a shell command such a ksh and proceeding commands are written to it and then the new shell dies after leaving.

But:

doing: String[] commands = {"ksh","klog username","password"};
Hangs!
I assumed it might be that a new terminal is created for the password prompt but then: echo password | klog username wouldnt work:
and java doesnt like: commands ={"ksh","echo password | klog user"};
for the same reason - could it be that Java cannot cope with prompts that do not display the shell's input?
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
I think it might have something to do with Bill's comment about consuming the process's output streams. See this Javaworld article for more detail.

Jules
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Another Runtime Problem