Linking Java to Windows Command

Hie all,
I would like to call a certain executable program from windows while i am running my program. I have tried looking at classes like System, Process, and Runtime. I wonder if i had missed out anything else. Say for instance i want to "Ping" and InetAddress which i obtained from my Java socket , can anyone tells me how can i do that.
Please help me out. Thank you so much and i am certainly waiting impatiently for a reply. Please mail your answer to me as well as posting it here. Thankz.
Regards,
Dave
[email protected]

I don't understand why you can't use Runtime.exec() to do this.
Runtime r;
Application app;
InputStream is;
r = System.getRuntime();
try {
    app = r.exec("ping 127.0.0.1");
    is = app.getInputStream();
    // read input stream ....
} catch (Exception e) {
    e.printStackTrace();
}To get the results, just read the stdout from the input stream.
Rhys

Similar Messages

  • Java with Windows Commands

    Ok, this is a pretty tricky one. Is there a way where I can tell java to execute windows commands? I mean, I would want to develop an app that when the user quits the java app, the machine would log out the current user using code. If somebody could give me any ideas how this can be possible, I would really appreciate it. The java app is going to be run from a JScript file that is going to be loaded as the user logs on to the machine. If anyone know of any way to do this with JScript as well, I would really aprreciate it. Thanks.
    Jose Bravo

    Maybe this is it, I'm not to windows savy but if you know the command to execute it should work. If it is a series of commands I recomend you create a batch file:
    (for java):
    import java.io.*;
    try {
    Process p = Process.getRuntime().exec("dir");
    // if you want to get the shell output //
    BufferedReader = new BufferedReader(p.getInputStream());
    } catch(Exception e) { }
    maybe this will work,
         --Ian                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Using Java in windows command prompt

    Hi,
    I don't know if I have been searching correctly, but I haven't found a solution to my problem through common search engines.
    I'm programming in java using vim (accessed through windows command prompt), and I've created classes, everything compiles fine.
    However, I wanted to test my classes my creating instances of them (i.e. objects) through the same windows command line (command prompt). I know you can achieve this by using interaction panes through third party programs such as Dr.Java and eclipse, but I was wondering if this can be done using the command line.
    Thanks
    Jaime

    Thanks Paulcw for your quick reply! :D
    I'm guessing I didn't word my question properly.
    Neither of my classes have a main method in them, so when I am trying to create instances (objects) of them, I would like to as if my command line was the main.
    For example:
    Class1 c = new Class1(parameters);
    c.moveRight();
    etc.
    I'd like to be able to use my classes methods from the command line, I think what I'm looking for is a batch, but I'm not sure.
    Thanks again,
    Jaime

  • Problem on Creating Unix Termial in java like windows command prompt

    hi all,
    i created an unix terminal using java swing(to connect unix server and executing commands). here i redirect the console output to textarea. The problem is i can't read the input from the textarea. and another problem is how to disable the editable option in the textarea before to the command read line. The terminal is like a putty. Any One Please give a suggestion for this problem.

    sabre150 wrote:
    georgemc wrote:
    LinaGsp wrote:
    5)then I run this command "jar cvfm MyJar.jar manifest.mf .class"If this is exactly what you did, and not a typo, that's probably your problem. Do you have a file called .class?It is more likely that the forum markup is getting in the way.Of course it is! D'oh! I seem to have a blind spot to that, I never take it into consideration...
    OP, listen to these guys, ignore this blind old fool :-(

  • Java Code Compilation in Windows Command Prompt

    Hi Everyone,
    I have been programming in java for quite some time now using an IDE (eclipse). I downloaded the following java file from:
    http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/JpegImagesToMovie.html#requirements
    and have downloaded the required JMF. The problem is that I want to compile and run this code in Windows Command Prompt; however, I keep receiving errors upon compilation because I do not know how to make jmf.jar be recognized as a library.
    Thx.

    javac -cp jmf.jar;otherJars file1.java file2.java file3.java...
    Run java and javac from the command line for an explanation of their options.
    Edited by: nclow on Jul 24, 2008 1:43 PM

  • Can't run java .class programs from Windows command line!

    I have tried to get a program that I wrote with the JDK to run from the Windows command line, but it is not working. I typed:
    java HelloWorld
    Where my .class was HelloWorld.class, a compiled java program. I spelled the name correctly (and I am in the correct directory), yet I get the following error:
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
    I think something is screwy with windows, but that's just me. Any ideas??

    Likely a CLASSPATH issue - try
    java -classpath . HelloWorldGood Luck
    Lee

  • Windows command length execeeded when add java options in opmn.xml

    Hi All,
    I have a Oracle AS 9i installed on Windows 2000. There are some requirement from my application that need to add additional java-options when start up OC4J. So, I updated the opmn.xml by add my things to <data id="java-options" > for start-parameters.
    But when I start up server, I got following information in ipm.log:
    06/05/16 17:18:06 create_proc: Windows command length exceeded: D:\ora9ias\jdk\bin\javaw.exe
    I have tried Oracle AS 10g with the same OS and java-options, the server can start up without any problem.
    Is there anyway to make Oracle AS 9i work in this situation?
    Thanks for any help.

    Hi again,
    Solved the issue simply by editing the xml file with sed:
    VAR1='OC4J_I413\/config\/java2\.policy -Djava\.awt\.headless\=true -Dhttp\.webdir\.enable\=false -XX\:MaxPermSize\=128M -Xms512M -Xmx1024M -XX\:AppendRatio\=3\"\/\>'
    VAR2='OC4J_I413\/config\/java2\.policy -Djava\.awt\.headless\=true -Dhttp\.webdir\.enable\=false -XX\:MaxPermSize\=256M -Xms512M -Xmx1024M -XX\:AppendRatio\=3 -Duser\.country\=SE -Duser\.language\=sv\"\/\>'
    sed "s/$VAR1/$VAR2/" opmn.xml > Newopmn.xml; cp Newopmn.xml opmn.xml
    This is a text string that contains start parameters and it can be found here:
    <category id="start-parameters">
    <data id="java-options" value="-server -Djava.security.policy=$ORACLE_HOME/j2ee/OC4J_I413/config/java2.policy -Djava.awt.headless=true -Dhttp.webdir.enable=false -XX:MaxPermSize=128M -Xms512M -Xmx1024M -XX:AppendRatio=3"/>
    //Kerstin

  • DOS Commands Used in Java Pgm, but command window should NOT be visible!

    Need a solution for the following.
    Problem: In a Java program, DOS Commands are used.
    Hence while executing it, the command window is visible for few seconds and later it is hided i.e once the processing of that DOS Command is finished.
    Solution Required: The Command Window should not be visible. The DOS Commands should be performed in the background with out making the command window visible.

    Problem:
    I am trying to run a executable file through java . But a command window always pops up. I want the command window not to pop up while the code is executed. Alternatively the rt.exec method should run in the background till the process is complete.
    I am using the following code in Java Swing application , where in when a user clicks a button the following method is invoked , which is turns invokes a windows a rasdial.exe file .Ex: rasdial MyConnection;
    Can someone help me on this. The below is a snippet of my code .
    public void callSerialOrInfraExe(String exeName) {
    executableFile = exeName;
    Runtime rt = null;
    Process process = null;
    boolean checkCon = false;
    try {
    rt = Runtime.getRuntime();
         process = rt.exec("rasdial " + executableFile);
    process.waitFor();
    checkCon = checkConEstablish();
    if (checkCon) {
    lblMsg.setVisible(true);
    cmdSubmit.setText("Done");
    cmdSubmit.setMnemonic('D');
    rdbSerialPort.setVisible(false);
    rdbInfraredPort.setVisible(false);
    jLabel1.setText(msgStr.toString());

  • Manipulating Windows command prompt through Java

    I am wondering if there is any way to manipulate simple Windows command prompt commands like color, cd, dir, cls through a java application. Any help or informative redirection would be much appreciated.

    BinaryBurnout wrote:
    I am wondering if there is any way to manipulate simple Windows command prompt commands like color, cd, dir, cls through a java application. Any help or informative redirection would be much appreciated.Realize that the Windows command prompt is an application (cmd.exe), and those commands are specific to that application.

  • Using JAR files when compiling in Windows command line

    Hi all,
    I can't get my JAR files to be recognized. Cananyone help with classpaths, syntax etc. when compiling Java in Windows??
    Thanks in advance.

    This page links to detailed descriptions of both the javac and java command syntaxes
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/tools.html#basic

  • How to execute a scenario from Windows command prompt

    Hi,
    I have a package which is executing fine from Designer. But the same scenario if I am trying to execute from windows command prompt, then it is giving error.
    The package is getting a refresh variable, passing to interface which is creating a file from table, this file is then getting FTP'ed to another server.
    I am executing following command -
    startscen OB_TAB_TO_FILE_PKG 001 ODICTX "-v=2"
    The error is -
    A JDK is required to execute Web Services with OracleDI. You are currently using
    a JRE.
    OracleDI: Starting scenario OB_TAB_TO_FILE_PKG 001 in context ODICTX ...
    java.sql.SQLException: socket creation error
    at org.hsqldb.jdbc.jdbcUtil.sqlException(jdbcUtil.java:67)
    at org.hsqldb.jdbc.jdbcConnection.<init>(jdbcConnection.java:2451)
    at org.hsqldb.jdbcDriver.getConnection(jdbcDriver.java:188)
    at org.hsqldb.jdbcDriver.connect(jdbcDriver.java:166)
    at com.sunopsis.sql.SnpsConnection.u(SnpsConnection.java)
    at com.sunopsis.sql.SnpsConnection.c(SnpsConnection.java)
    at com.sunopsis.sql.i.run(i.java)
    DwgJv.main: Exit. Return code:-1
    Please let me know where I am going anything wrong.
    Thanks,
    Himanshu

    Hi,
    you need to make the necessary changes to the %odi%\bin\odiparams.bat config file, under the "Repository Connection Information" section so that startscen knows how to extract metadata from your repository.
    You apparently have left the default settings to the Hypersonic demo repository. Is that the technology your repository is hosted on?

  • Java with Windows xp

    how to run java programmes in windows xp thru command prompt window.
    Whenever i open command prompt window i have
    c:\Documents and Settings\owner>
    I need to get access to my java folder,how do i get there thru command prompt window

    The Windows command "cd" allows you to change the current directory. In fact if you type "help" at the command line it will list all of the commands you can use there. But I strongly suggest you know how to use your operating system before you start to use it to write programs.

  • Execute windows command line to a file

    Hi,
    I would like to run a windows command line from Java and output the result to a file.
    eg.
    cmd> mycommand hello > output.txt
    in windows ">" is to output the result to a file.
    I've tried
    String command  = "mycommand hello > output.txt";
    Process process = Runtime.getRuntime().exec(command);But that exec() didn't output to a file.
    Can someone give me an example on how to do this?
    Thanks

    You are falling for one of the traps described here. The redirection operator '>' has to be interpreted by a shell or command processor. On windows this would be
    String command  = "cmd.exe /C mycommand hello > output.txt";and on Linux this would beString command  = "sh -c mycommand hello > output.txt";You should read all 4 sections of the traps article and implement ALL the recommendations or you will be back here again.

  • When I click on a link, a new window opens but is blank and says "stopped" at the bottom

    Happens on any website.eg-if I am looking for a quote on moneysupermarket.com and I lick on the required link, a new window will open but it will be blank and in the bottom left hand corner the word stopped appears

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")
    There are other things that need attention.
    Your above posted system details show outdated plugin(s) with known security and stability risks that you should update.
    # Shockwave Flash 10.0 r32
    # Java Plug-in 1.6.0_06 for Netscape Navigator (DLL Helper)
    Update the [[Managing the Flash plugin|Flash]] plugin to the latest version.
    *http://www.adobe.com/software/flash/about/
    Update the [[Java]] plugin to the latest version.
    *http://www.oracle.com/technetwork/java/javase/downloads/index.html (Java Platform: Download JRE)

  • Button activation in Java vs windows

    first, let me say I am a novice programmer.................
    I am attempting to activate a "push button" in a java application (AWT) which is deployed on a windows 2000 environment (a commerical software package which controlls a piece of equipment). I am attepting to activate a button in this application by establishing a windows level control over the window with the push button and acivete the button with windows commands all writtin in C#.net. I wrote a routine to esstablish a focus on the window with the "push button" and am able to manually depress the space bar to activate the button, however when I try to simulate this by activating the windows "space bar" key stroke command the java button depresses but the background java application does not activate. Is there a special command sequence that JAVA recognizes to initiate an action via "spacebar" press?

    crosspost

Maybe you are looking for

  • Satellite Pro U300: DVD issue - error: cannot output to external monitor

    Hi, I was having problems playing a dvd on my U300. Basically the software would load but when I tried to play the dvd it said "cannot output to external monitor". Having gone through all options I could not find anything to stop this happening. I th

  • Library works, but cannot edit or magnify

    I installed iPhoto '08 over iPhoto '06, then upgraded to 7.0.2. Everything (events, keywords, search, thumbnails) works except viewing/editing my photos full size. With both 7.0.0 and 7.0.2, double click to magnify does nothing. If I try to edit, the

  • PDFmaker in windows

    Hi, I got a new MacBook Pro and installed my copy of Microsoft Word 2004 on it (I'd previously been using this on my intel-based iMac). Now, every time I change a document and then quit out of Word, I get the usual "do you want to save this document"

  • After installing Mavericks I can't copy music files to an external music server, worked fine before mavericks

    After installing Mavericks, I can't copy or move files to a music server running Vortexbox(Fedora Linux based). I get a cannot perform operation, you do not have permissions for some items. The permission arrow in get info shows I have both read and

  • Photoshop layer move and layer duplicate event ids

    I am running PSCC 2014 on a mac. I work with a wacom table and keyboard shortcuts. I work fast without looking look at the keyboard. Often end up moving layers, duplicating layers inadvertently by pressing the wrong keys. I have identified the keyboa