Reading newly opened command prompt output

I need to use SSH to connect to a server. Rather than downloading a third party SSH API, I would like to use Putty which is already on my computer. The problem is that when using Putty from the command line to connect to a server it opens the connection in a completely different command prompt window instead of the original window. How would I read the output from the new window? I believe this code would have worked if it opened the connection in the same command prompt window...
try{
File test = new File("c:\\program files\\putty");
Runtime rt = Runtime.getRuntime();
Process output = rt.exec("cmd /c putty.exe -ssh username@host", null, test);
BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream()));
String line = null;
while((line = br.readLine()) != null )
{ System.out.println(line); } // display process output
int exitVal = output.waitFor(); // get process exit value
System.out.println("Process Exit Value : "+ exitVal);
catch(IOException ioe){
System.err.println(ioe);
catch (Throwable t) {
t.printStackTrace();
}

web definition of 'come unstuck' :
come unstuck (British & Australian)
if a person or something they are trying to achieve comes unstuck, they have problems which cause them to fail. Athletes who don't prepare properly for the humid conditions will certainly come unstuck. The negotiations came unstuck over disagreements about the wording.

Similar Messages

  • Command Prompt Output to a File

    hi,
    i am new to java, i would like to write a program which executes a command in command prompt, giving some result and want to read this command prompt output to a file like this:
    1) first i need to exeucte "dir c:" command which will give the details fo that particular directory
    2) the output displyed on the command prompt by executing the above command has to be read into a File.
    help me with some code snippets to do this.
    Thanks in advance.

    could you please elaborate the explanation interms of
    java code snippets?
    rofl
    Read this.
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=3

  • Host command, change directory where it opens command prompt

    I'm using the HOST command to host out to the command prompt. What I want to know is how to change the directory that the command prompt opens up at. I want it to open up at the c:\ but instead it's opening up at in the forms60 path where forms is installed.
    Thanks in advance

    Hi Viktor,
         What i could understand from your question is that in the FTP server you'll be writing a file in folder A and once the writing is done you need to get it moved to Folder B using a 'CD' OS command. But this OS command is not allowed in the FTP server.
        If that is the case then it will be better to write the file directly into the Folder B. But in the file adapter use the option 'Use Temporary File'. In that case until and unless the file is written fully the file will be having the name .tmp or so.
        The advantage will be the third party server could be polling the folder B for a file *.txt in that case it won't pick this .tmp file.
    Cheers
    JK
    PS: Award points if this helps you.

  • Open command prompt via applet?

    Hi guys
    I am expecting this code to open a command prompt on the user's PC. I have the same "cmd.exe /k" in a test.bat file which does what I expect. This code, however, doesnt seem to be opening a command prompt, but the applet is launching fine. Any ideas?
    Thanks in advance.
    import java.applet.*;
    import java.awt.*;
    import java.io.IOException;
    public class MyApplet extends Applet {     
         private static final long serialVersionUID = 1L;
         public void init() {
              setBackground(Color.WHITE);
         public void start()  {
              try {
                   openCMD();
              } catch (IOException e) {}
         public void stop() {
         public void paint(Graphics g) {
              g.drawString("Applet Started", 10, 10);
         public void openCMD() throws IOException {
              System.out.println("opening cmd..");
              Runtime.getRuntime().exec("cmd.exe /k");          
    }

    Hi, that code for opening the cmd through n applet is great and works perfectly....
    Does anyone know how to then enter a filename into this code, which will open the cmd, and then open another file?
    I have the following code:
    String[] cmd = new String[6];
    cmd[0] = "cmd.exe";
    cmd[1] = "/C";
    cmd[2] = "start";
    cmd[3] = "cd";
    cmd[4] = "C:\\path";
    cmd[5] = "javaw";
    cmd[6] = "FileName";
    Process process = Runtime.getRuntime().exec( cmd );
    But this does not seem to work at all. if i delete cmd[5] and cmd[6] it works and opns up the cmd with the specified path, but i cannot get it to open the java file or any file for that matter.
    Any help would be great!

  • Command prompt is not opening

    Hi,
    i tried to open 'COMMAND PROMPT'. but not able to open. what is the problem and where should i need to change the settings for command prompt.
    Regards,
    venkat.

    I'm going to assume you are on Windoze and are talking about a Windows Command prompt. If so, click on the Start button, then click on Run and type cmd and then click OK.

  • How to read Command Prompt?

    Hello!
    In my application i need to read information from Command Prompt. From other programmers i knew that method : System.in.read(); state for it. But I get the whole bunch of error messages from compiler.
    If you know concrete URL's or web sites where I can learn about this function, please reply to me.
    I will appreciate any help.
    Thank you in advance
    Michael

    System.in.read() throws a java.io.IOException. Did you put try/catch statement to catch this exception ?
        try {
            System.in.read();
        catch(java.io.IOException ioException) {}

  • How to read multiple lines from a command prompt?

    I usually read from a command prompt like this:
    String answer;
    System.out.println("Please enter the required data");
    try {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    answer = reader.readLine();
    reader = null;
    } catch (Exception e) {
    System.out.println("There was an exception trying to read " + e);
    answer = "";
    This has worked fine for years when all I wanted was one line answers.
    Now I am trying to prompt for multiple line answers. Is there a way to read into a string array rather than just a string? What class would I use for that?
    Thanks a lot!

    The easiest approaches would be to read a line at a time until you've read enough lines, whether by a known fixed line count, or a token count, or by reading some sentinel toek, OR read a token at a time using Scanner.next() until you've determined you're done. Which one is more appropriate depends on your situation.

  • Open a command window and send some keystroke to the opened command window

    Hi All,
    I am trying to open command prompt and send some key stroke to that command prompt. Here I am using Robot to send keystroke. But the problem is, the keystrokes are not sent to the prompt. I guess I need to activate progamitically the command prompt to accept the keystrokes . Please find the code below ( as I did).
    try
    String command = "cmd.exe /c start";
    Process child = Runtime.getRuntime().exec(command);
    Robot robot = new Robot();
    Thread.sleep(5000);
    String lol = "indranil";
    for(int i=0;i<lol.length();i++)
    robot.keyPress(lol.charAt(i));
    int g = lol.length() - 1;
    robot.keyRelease(lol.charAt(g));
    catch (Exception e) {}
    I guess I am doing some mistake here while sending the keystroke/openning the command prompt. Can anyone please help me how can I open a command window and send some keystroke to the opened command window. I am in fix.
    Thanks,
    Indranil

    The first thing to do is read the API and examples for the Robot class.
    Also check out this thread with a similar discussion: [http://forums.sun.com/thread.jspa?threadID=5385677]
    The short spoonfed answer - keyPress() and keyReleaseI() do not take chars. Read up on KeyEvent

  • Running multiple commands in command prompt

    Hi
    I am having the following scenario
    open command prompt
    open xilinx command prompt
    switch to xmd console
    run a set of commands
    print the final output to screen
    I am having the following doubts
    Can system exec.vi take multiple commands as standard input?
    If yes what is the delimiter?
    If no what other options I have to achieve my goal
    Thanks

    Why not write a batch file and start that with System Exec?
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to get the drive letter of a Volume using command prompt

    Using windows command line tools i want to get the drive letter of a volume, by specifying its volume number.
    For example i have a HDD with 2 volumes: Volume-0 and Volume-1
    I want to set a Variable say 'Letter'=<Drive Letter> such as
    SET Letter=<Command> <Volume Number>
    Is there any command which can do this for me...
    Thanks...

    Hi,
    You can use the diskpart tool to assign a drive letter to the drive by specifying the volume's number.
    1.Open Command Prompt.
    2.Type:diskpart
    3.At the DISKPART prompt, type:list volume
    Make note of the number of the simple volume whose drive letter you want to assign, change, or remove.
    4.At the DISKPART prompt, type:select volume n
    Select the volume, where n is the volume's number, whose drive letter you want to assign, change, or remove.
    5.At the DISKPART prompt, type one of the following:assign letter=L
    Where L is the drive letter you want to assign or change.
    For more detailed information, you could refer to the article below:
    Assign, change, or remove a drive letter
    https://technet.microsoft.com/en-us/library/cc757491(v=ws.10).aspx
    Best Regards,
    Mandy 
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • Command Prompt Blue Screen in Windows 10

    McAfee 8.8i isn't supported yet until patch 6 which is due mid-end of this month eitherNod32 V5 seems to work ok though - although I don't know the official stance on that.http://www.bitdefender.co.uk/support/is-bitdefender-2015-compatible-with-windows-10-1451.htmlAlso worth reading if you're not already awarehttp://community.spiceworks.com/topic/1099226-antivirus-maker-bitdefender-hacked-customer-data-sold-...

    Hello All,
    I recently upgraded to Windows 10 and notice that when opening up command prompt, typing in command, then closing by clicking on the X button to close the Window, it will immediately blue screen. When I open command prompt, do a command, then type "exit" in command line, it closes the window with no problem. I haven't see any Microsoft forum reporting any issues so wasn't sure if this is a mass issue that will be rolling in soon or just isolated to my computer.
    Any advice would be helpful.
    This topic first appeared in the Spiceworks Community

  • I Need Help Adjusting Command Prompt Directories

    I have the satellite L505D---S5983 and I need to change my prompt from C:\Users\Brandon>. I have tried every search I can think of but nothing is working for me. Please help. I need this to be fixed ASAP, I am a app developer for android and I need to get back up and running.

    Satellite L505D-S5983  
    I need to change my prompt from C:\Users\Brandon>.
    Brandon, make a shortcut to cmd (%systemroot%\system32\cmd.exe) and name it Command Prompt.
    Right-click the shortcut, click Properties, and put the folder you want (c:\, for instance) in the Start in: field on the Shortcut tab.
    I find it's a good idea to open command prompts in elevated mode. To do that, click the Advanced button on the same tab and set Run as administrator.
    -Jerry

  • Sound problem and command prompt problem

    hi
    My new cq40 610tu compaq laptop works with only left side speaker is it build with only one left side speaker?  Is there no dual speaker?  But with head phone two headphone speaker works properly.  tell me details.
    another problem when we open command prompt in winxpSP2 it is not stable after few seconds it turns off automatically.  When I type large things in ms word 2003 cursor goes different place automatically.  whats the problem? 
    I purchase this laptop just 15 days ago.  What's the solutions?
    thanks
    Dhiman

    Hi kbzone,
    ... there should difinitely be no sparks  ) I recommend that you start with checking the wiring ... is the computer connected to earth, is the amplifier? Are they connected via the same power socket? Are you sure that the amplifier is OK?
    Then, will it be possible to have any sound from the card if the amplifier is not used? You can try removing cards, uninstalling drivers and then re-install ...
    It is well possible that by now you have damaged your soundcard, btw
    Hans

  • Using Java To Open Terminal/Command Prompt

    I wanted a .jar file to open the terminal/command prompt on execution so that i can use System.out to display all the information needed...Is this possible? If so what code can i use to open the command prompt from java
    Thanks a lot ppl ;)

    Terminal prompt is plataform dependent, I would not advise you to do that. If your system outs are logging, i sugest you to use any logging api. If you are trying to display text information to the user, open any text widget and output there.
    May the code be wiht you.

  • When I open firefox (note: I got firefox version 28.0 and Karspersky security 2014) I get a black screen, looking like a command prompt window, in firefox.

    Hi,
    When I open firefox (note: I got firefox version 28.0 and Karspersky security 2014) I get a black screen covering the whole firefox window and it looks more lika a big command prompt window, in firefox. What is it?
    Regards
    Jean

    Huh, that's a new one...
    Can you try Firefox in [[Safe Mode | Safe Mode]] to see if the problem goes away. I'm thinking it's an extension.
    *Run ''firefox.exe -safe-mode'' in the search bar on the Start Menu. (Make sure Firefox is closed)
    Have you added any new extensions recently around the time this started happening? Your system details shows the following:
    *Adobe Acrobat - Create PDF 1.2 ([email protected])
    *Anti-Banner 14.0.0.4917 ([email protected])
    *Dangerous Websites Blocker 14.0.0.4917 ([email protected])
    *Kaspersky URL Advisor 14.0.0.4917 ([email protected])
    *Troubleshooter 1.1a ([email protected]) '''This is default so this isn't the problem.'''
    * Virtual Keyboard 14.0.0.4917 ([email protected])

Maybe you are looking for

  • How to pass the key pressed in javascript

    I'm asking this question here as I could not find the needed help elsewhere . I don't know how to pass the key pressed in the function on OnKeyPress event . I'm trying the following : <input type="text" name="a" onKeyPress="check();"> I want to pass

  • Sign In To Facebook Problem

    I just discovered the 'export to' feature in Bridge and was successful with an export to Flickr however cannot export to Facebook.  After dragging and dropping my photo on FB icon then clicking on the arrow next to the cross the sign in screen comes

  • Need help on data Conversion

    Hi Gurus, Please help me with process and validations in following conversions. Sub Inventory conversion Hr Locations conversion. I am working on R12 implementation project. Thanks in advance. GVK.

  • Poplist and muti-record block navigation

    Hi. I have a form with a multi-record block and a poplist on each record. When a certain item is TRUE on a record, I want the poplist button to be disabled and enabled when the item is FALSE. The button is normally enabled and I disable it when neede

  • F4 help on select option.

    Hi all, My requirement is iam  fetching the values from  SCMG_T_CASE_ATTR table. in selection screen i have given range for stat_order no field. if the user enters the values for that range then i should allow the user  only to  enter the values whos