Results 1 to 5 of 5
  1. #1
    stevieger is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default returning to command line for several command line entries

    I am trying to simulate the execution of a couple of commands and am unsure of the best way to go about this. What I'm trying to simulate is the following commands:

    1. ftp hostname.com
    2. username
    3. password
    4. cd directory
    5. ls

    So as is evident from the above I am ftp-ing into another computer(a UNIX box, not sure if it changes anything), changing to a specific directory and listing the contents of the directory. I just need to create a simple method to execute those sequential commands so I can access the list of that directories contents.

    my code so far:
    Java Code:
    Runtime rt = Runtime.getRuntime();
    Process first = rt.exec("cmd.exe /c start cmd.exe /k \"ftp hostname.com\"");
    When running this I get the command line to open and its asking for the username so all works fine so far but then i add to my code something like:

    Java Code:
    Runtime rt = Runtime.getRuntime();
    Process first = rt.exec("cmd.exe /c start cmd.exe /k \"ftp hostname.com /k\" && \"ftpusername\"");
    I get a command line telling me what the ftp command is used for. So my problem is running these sequential commands, I thought the /k made the program return to the command line which then would allow to enter in the next line needed but this doesn't seem to be the case. I've tried different variations from what I've been reading on this process rt.exec method but I can't seem to get it. Any help is appreciated, thanks.

  2. #2
    stevieger is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default executing commands in sequence

    I have some commands that I can execute manually at the command line to get a directories contents and am trying to program the same thing to happen automatically so I can read in the directories contents and use that for something else. Manually I connect to another PC(a UNIX box) using FTP and once connected I change the directory (cd directory...) and then enter an 'ls' command to list the contents.

    The main part of the code that executes the commands that I have so far is:
    Java Code:
    Runtime rt = Runtime.getRuntime();
    Process first = rt.exec("cmd.exe /c start cmd.exe /k \"ftp hostname.com\"");
    The result of this is equivalent to me opening the command line and entering 'ftp hostname.com' and it asking me what the username is, which is what it should be, so I add to it:

    Java Code:
    Runtime rt = Runtime.getRuntime();
    Process first = rt.exec("cmd.exe /c start cmd.exe /k \"ftp hostname.com /k\" && \"ftpusername\"");
    Using the same logic I expect this much to show me a command line the entered 'ftp hostname.com' (hits enter) enters in the ftpusername for the username(hits enter) and should be asking me for the password, however this is not happening!

    I get a command line window showing me the different arguments to use with ftp. I'm confused as to why this is happening and the /k is not returning to the command line entering the commands in their specified sequence.

    Any help is appreciated.

    Regards,
    Steve

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,533
    Blog Entries
    7
    Rep Power
    20

    Default Re: returning to command line for several command line entries

    I merged both of your threads because they both deal with the same problem; don't double post please.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: returning to command line for several command line entries

    stevieger, you didn't bother to return to the first thread you started. Why should we expect any better behavior this time round?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    stevieger is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default Re: returning to command line for several command line entries

    Did not know I needed to formally close threads, sorry, just trying to get some help.

    Sorry for double posting just thought it was in the wrong category and realized I could have explained a little better. I'll delete the other post first if it happens again.

Similar Threads

  1. command line help
    By stuckonjava in forum New To Java
    Replies: 5
    Last Post: 12-09-2012, 06:29 AM
  2. Replies: 16
    Last Post: 09-17-2011, 02:41 AM
  3. can i run line by line command in netbean?
    By choconlongxu in forum NetBeans
    Replies: 1
    Last Post: 07-19-2010, 08:41 PM
  4. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •