Trying to find a way to execute from command prompt using java....

I want to find a way to execute a command from the command line using a java program this is my code:
import java.io.*;
public class SQLHopefully
     public static void main(String[] args)
          try{
          Runtime rt = Runtime.getRuntime();
          Process proc = rt.exec("cmd /k start cmd.exe");
          OutputStream out = proc.getOutputStream();
          System.out.println(out);
          out.write("test.txt".getBytes()); //I THOUGHT THIS WOULD WORK
          InputStream stdin = proc.getErrorStream();
          InputStreamReader isr = new InputStreamReader(stdin);
          BufferedReader br = new BufferedReader(isr);
          String line = null;
          while ( (line = br.readLine()) != null) {
          System.out.println(line);
          stdin = proc.getInputStream();
          isr = new InputStreamReader(stdin);
          br = new BufferedReader(isr);
          line = null;
          while ( (line = br.readLine()) != null) {
          System.out.println(line);
          int exitVal;
          try {
          exitVal = proc.waitFor();
          } catch (InterruptedException e) {
          throw new IOException(e.getMessage());
          if (exitVal != 0) {
          throw new IOException("Exit value was " + exitVal ");
          }catch(IOException e)
          {System.out.println("ummmmm");}
I hope my code is readable. I am trying to get the command prompt that comes up from the Runtime.exec() to run a file called "test.txt" I know it would be easier to just do it by executing it from java but I want to see if it is possible this way. I thought the out.write would do the trick but I was wrong. Somebody help please....
Nate

First read this article:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Second, you should probably send the Enter key to the shell if you want anything to happen. (Not that I know whether it will work, but I do know it won't work if you don't press Enter.)

Similar Messages

  • Cant See RTF Files in JAR but can when running program from command prompt

    posted August 16, 2005 08:26 AM
    Hi ALL:
    I have a Java Swing APP. It has Menus which displays information through File I/O in a JEditorPane.
    When I run my program from Command Prompt using "java myApp" it shows these RTF Files as it is.
    However when I run them after converting Directory into a Executable JAR FILE, it fails. I get a blank JEditorPane. My RTF files are in the CORRECT PATH, just dont get displayed. Rest of the APP works fine.
    Chetan
    any suggetsions

    posted August 16, 2005 08:26 AM
    Hi ALL:
    I have a Java Swing APP. It has Menus which displays information through File I/O in a JEditorPane.
    When I run my program from Command Prompt using "java myApp" it shows these RTF Files as it is.
    However when I run them after converting Directory into a Executable JAR FILE, it fails. I get a blank JEditorPane. My RTF files are in the CORRECT PATH, just dont get displayed. Rest of the APP works fine.
    Chetan
    any suggetsions

  • How to execute external  spawned process using  java

    Hi,
    I am executing PGP from command line using java.
    For adding the public key I use Runtime object like this
    Runtime rt = Runtime.getRuntime();
    Process process = rt.exec("pgp -ka "+"d:/Mangesh/pubkey/sandy.asc "+"C:/PROGRA~1/NETWOR~1/PGPNT/keyrings/pubring.pkr");PGP is executing this but inbetween it asked for confirmation "Do you want to add public key (y/n)"
    I am providing data to process this way:
    PrintWriter pw = new PrintWriter(new OutputStreamWriter( process.getOutputStream()));
    pw.write('y');
    pw.flush();But after this their is no execution from PGP and console remains until I closed it.
    PGP is waiting for ENTER KEY
    How can I provide ENTER KEY from java
    This is right method ??? or any other options are available??
    I am awaiting for your valuable suggestions .
    Regards
    Man479

    On Windows the "enter key" consists of two characters: carriage return and a line feed (\r\n). You may have to send both. If that doesn't work, pgp is not reading the reply through stdin, only through the console, and there's no way to pass the 'y' to it through Java.

  • Error while Invoking SQLPLUS from Command Prompt

    Hi All,
    I am trying to Connect to Oracle through sqlplus from command prompt of windows and getting this Error:
    C:\Documents and Settings>sqlplus
    SQL*Plus: Release 10.2.0.1.0 - Production on Thu Dec 28 10:08:43 2006
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Enter user-name: scott
    Enter password:
    ERROR:
    ORA-12560: TNS:protocol adapter error
    set ORACLE_SID=database_name was set
    Anyone ever got this error or has any idea could you please help.
    Thanks.

    Try
    set LOCAL=<tns_name>
    Regards
    Kurt

  • Can't create database from command prompt

    I am using Oracle 9i over Win XP. I can create new database using OEM wizard without any problem. However, when I try to create new database from command prompt, using following commands, I get an error.
    sqlplus /nolog
    connect / as internal (when I issue this I get message TNS no listener)
    CONNECT SYS/password AS SYSDBA (can't understand how to use this, I don't have password because I've not created the database)
    Can anyone help me how to create new database from command prompt?
    Thanx

    "TNS No Listener" => Start the listener
    To be connected as SYSDBA you dont need a password if your are logged in the DBA group, you just have to :
    PROD_:id
    uid=102(oracle) gid=103(oinstall)
    PROD_:sqlplus "/ as sysdba"
    SQL*Plus: Release 8.1.7.0.0 - Production on Wed Jul 23 11:46:50 2003
    (c) Copyright 2000 Oracle Corporation. All rights reserved.
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.4.0 - Production
    SQL> show user
    USER is "SYS"
    SQL>
    Fred

  • I am trying to find a way to play music from my I-tunes Library outside using wireless speakers..  It this possible??

    I am trying to find a way to play music from my I-tunes library outside of the house using the Ariport Express and wireless speakers if possible.. I would like to purchase some outdoor capable wireless speakers which will receive the signal from the airport Express.. Is this possible???  Do you knwo what speakers I need to buy???  I do not want to have to run speaker wires from the Airport Express to these outdoor speakers..
    Thanks for the help

    I still have the email and the order number but they are no use to me because it is more than 180 days since I ordered this from them.
    The registration cade is contained in the email Apple sent you on purchasing.

  • I'm trying to find a way to move pictures from Preview to iPhoto. Tried "rebuilding  library"...nothing happens.  Help!

    I'm trying to find a way to move pictures from Preview to iPhoto. Tried "rebuilding  library"...nothing happens.  Pictures ssomehow wound up in Preview after I needed to do a clean install (Snow Leopard) and moved files from an external drive. Help!

    If you saw the images with Preview in the other iPhoto Library, than try to open iPhoto with that Library:
    http://support.apple.com/kb/PH2505
    If the Photos are there, replace the iPhoto Library in your Pictures folder with the one from the external.  (posted by Keith)
    My response:
    The pictures don't appear in Preview in the other user account.  They also don't appear in the external drive (!!!????).  I discovered I can get the pictures into iPhoto by saving from Preview to the desktop, then importing into iPhoto, but only one at a time.
    Clearly the files are on the hard drive somewhere, but where?  The  'iPhoto library" icon that appears in my Pictures folder is a "package" which can't be opened on it's own....it's only able to be  imported into Preview.
    This feels like the Twilight Zone to me.....

  • I had a drive failure and lost the iWeb file along with other things.   I did manage to save a lot of user file documents but I don't see or   recognize the my iWeb site file. It was on a 15" G4 Titanium pb. I'm trying to find a way, using version 2.0.4

    I had a drive failure and lost the iWeb file along with other things. 
    I did manage to save a lot of user file documents but I don't see or 
    recognize the iWeb site file. It was on a 15" G4 Titanium pb.
    I'm trying to find a way, using version 2.0.4 of iWeb on a different 
    pb to recover the file into the iWeb app or a way to download the site into iWeb.
    There are 6 pages of images and text, and it 
    would be a task for me to recreate the whole thing again. I did 
    download the site but I don't know how or if I can get iWeb to see it and open it.
    Does anyone have any knowledge about this? The link to my site:
    <http://web.mac.com/danauerbach>
    Any suggestions will be most appreciated.
    dan auerbach
    [email protected]

    Unfortunately iWeb cannot read or import previously published files, only generate them.  You'll have to recreate your site from scratch.
    However, Chapter 2.3 on the iWeb FAQ.org site has tips on using some of the existing files, image, audio, video, etc., from the published site in the recreation of the site.
    OT

  • HT204269 I can't find MobileSync/Backup/ in the Application Support folder in Library, I'm trying to find my phone back up from a few days ago before I bought my new iPhone, but when I searched on iTunes backup it has been replaced by the back up the day

    I'm trying to find my phone back up from a few days ago before I bought my new iPhone, but when I searched on iTunes backup it has been replaced by the back up the day after that. Now all my data from my old phone is lost including some really important things. Also before that iTunes wouldn't let me sync my iPhone 5s data to my new iPhone 6 Plus, saying that the data is corrupt, that's where all this trouble started. I've been trying to back-up the old phones data so I can access it, but it's been replaced when ever I plug the new phone in, and no the 'sync automatically when connected' is not ticked. Please help me find my back ups.

    Your iCoud account remains in iCloud even if your device is restored.  (In fact, you can't delete an iCloud account from iCloud, you can only choose to stop using it.)  If the device is restored, or it may no longer be signed into your iCloud account but your account will still exist in iCloud.

  • I just purchased the SX60 and have been trying to find the way to change the "startup image".

    I just purchased the SX60 and have been trying to find the way to change the "startup image". I have the SX40, Sx30 SX1 and all allow me to change the startup image and the sounds through MyCamera. When I opened MyCamera, it tells me that it won't work on my model. Does anyone know how to change the startup image? In the menu it gives me the choice to either have it on or off. Thanks so much!

    Looks like Canon has changed what they ship with the newer cameras. My SX50 came with a disc & no paper manual. Because of that I searched the Canon site (USA site) & found the program set you need to download (according to what it says). Now there are different versions based on your operating system so for my search I've chosen Win 8.0 & the program file recommended is
    File Description   Date Size
    Digital Camera Software 4.3 [Windows]
    09/16/14
    22.26 MB
    File Name: dcsw-4-3-0-2-9l.zi
    "A skill is developed through constant practice with a passion to improve, not bought."

  • I have been trying to find a way to use something a substitute for Adobe Flash on my IPAD2.

    I have been trying to find a way to use something a substitute for Adobe Flash on my IPAD2. Can anyone help?

    In my opinion, the is the best way to find the information that you are seeking.
    http://www.google.com/search?client=safari&rls=en&q=apps+athat+allow+flash+conte nt+on+iPad&ie=UTF-8&oe=UTF-8#hl=en&client=safari&rls=en&sa=X&ei=C2jOTsjiNcbi0QGN ssgj&ved=0CBwQvwUoAQ&q=apps+that+allow+flash+content+on+iPad&spell=1&bav=on.2,or .r_gc.r_pw.,cf.osb&fp=536d9da873bf088a&biw=1041&bih=653

  • I just purchased a MacBook Pro Retina. Checked my OSX and it is version 10.8.1... trying to find a way to upgrade to a higher version. In the app store it doesnt show the update nor downloading the new Mountain Lion OXS doesnt work. Please help

    I just purchased a MacBook Pro Retina. Checked my OSX and it is version 10.8.1... trying to find a way to upgrade to a higher version. In the app store it doesnt show the update nor downloading the new Mountain Lion OXS doesnt work. Please help

    hienn,
    Not yet. There was an upgrade page to 10.8.2 for the late 2012 models but it's down now. I have to assume that Apple pulled it because of some bugs. I would look for something next week, more likely than not. In the meantime, the OP should be good with 10.8.1 until the update shows up again.
    Clinton

  • I have road runner webmail and I am trying to find a way to import my addresses.  I can't imagine that I have to type them all in!ai

    I have road runner webmail and I am trying to find a way to import my email addressess to my imac pro.  I imagine that I don't have to type them all in! 

    Sorry but I know of no app that will display keywords during  Slideshow. Several - including iPhoto - will display the title and you can change lots of titles quite quickly using the Batch Change command. As to what gets displayed during a ScreenSaver that's a matter for the individual screensaver.
    Regards
    TD

  • HT1689 I purchased TV shows, I was billed for them, but they won't play on my Macbook because it says they are a certain HD that doesn't work - I am trying to find a way to return the shows or buy them in the right format

    I purchased TV shows, I was billed for them, but they won't play on my Macbook because it says they are a certain HD that doesn't work - I am trying to find a way to return the shows or buy them in the right format

    I am using MAC OSx 10.5.8 (9L31a) as my operation system.  The TV says "No signal.  Check connected device's power, cable connection and source selection."  Seems to me that that goes in hand with what the Samsung tech said about the Mac needing to be forces to use the external display.  But how do I do that?

  • My ipod touch was stolen and im trying to find a way to track it down

    my ipod touch was stolen and in trying to find a way to track it down.

    IF you set up find my ipod on the ipod and it is on and it is connected to wi-fi and the thief has not restored it, then you may be able to get an approximate location using icloud.
    Otherwise it cannot be tracked.

Maybe you are looking for

  • Using XVID with Premiere Pro CS3?

    I'm trying to export to video using XVID encoder, two pass. I start the first pass, an XVID status window appears, and then it appears to get stuck. Has anyone here used XVID with Premiere Pro CS3? If so, any suggestions?

  • Acrobat Calculated Date JavaScript

    Hi, I was wondering if anyone may assist me with this. I have a form that people complete for travel. Certain things have to be submitted not later than specific days before their travel. Beginning of form has travel date Q.1: mm/dd/yy Based on the t

  • Single form access

    Hi Guyz, I have created my own tool bar and menu bar and have display filed DIS_FLAG Y/N when user login DIS_FLAG display YES/NO i use the below code on WNFI :CAN_BLK.DIS_FLAG:='Y'; :GLOBAL.FLAG:=:CAN_BLK.DIS_FLAG;and in menu item on employee form i

  • For object RF_BELEG LT, number range interval 50 does not exist FBN1

    dear all system showing this message (For object RF_BELEG LT, number range interval 50 does not exist FBN1)

  • Difference in file size in photoshop and bridge

    when I save an image in photoshop (file size 26mb) it  shows as a 70.7 mb in bridge or window explorer. Why?