This week's book giveaway is in the Agile forum.
We're giving away four copies of Fixing your Scrum and have Ryan Ripley & Todd Miller on-line!
See this thread for details.
Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Another Runtime Problem

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Am I missing something, the commands in the array dont appear to get processed at all
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm ive just tried it on a linux machine and im getting the same problems
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
side note: why aren't you using Java to perform what you are attempting?

Your system commands look like a broken approach.
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic