Oops - meant to say "Controlling Legacy DOS program from Java ..."

Sorry - don't know what I wasn't thinking - muddled up my post title!
As part of my final year project, I'm trying to control a camera mount automatically using stepper motors. This will then be used for robotic navigattion. Most of my code is written in Java, but I have been given some old C code to control the motors with. One loaded, it sits in an infinite loop that waits for keyboard input, resonds, loops, and so on ...
I'm trying desperately to find a way of issuing commands to this program from my Java programs. I tried to implement a listening server in the C code but got a bit bogged down. Now wonder if I can use the
exec and getOutputStream methods in Java to control the Dos program...?
Any ideas very very welcome. I've reached hair pulling out time!
Ben Barker

Everything is now woeking...ish:
I can now make the below java program bring up, for instance, windows calculator or notepad.
I can't test it on the main code yet at I don't have the right computer in front of me. However, I decided to try to test it by runing cmd using ...exec("cmd"), then printing a command to the output stream to make windows calculator run. This caused precisely nothing to happen ...
Any ideas?
import java.io.*;
class java_test
public static void main(String[] args)
          try
          Process p= Runtime.getRuntime().exec("cmd");
          InputStream is= p.getInputStream();
          OutputStream os= p.getOutputStream();
          PrintStream printStr = new PrintStream(os);     
          printStr.println("calc.exe");
          catch (Throwable t)
          t.printStackTrace();
}

Similar Messages

  • Controlling legacy DOS program from linux

    Hi,
    As part of my final year project, I'm trying to control a camera mount automatically using stepper motors. This will then be used for robotic navigattion. Most of my code is written in Java, but I have been given some old C code to control the motors with. One loaded, it sits in an infinite loop that waits for keyboard input, resonds, loops, and so on ...
    I'm trying desperately to find a way of issuing commands to this program from my Java programs. I tried to implement a listening server in the C code but got a bit bogged down. Now wonder if I can use the
    exec and getOutputStream methods in Java to control the Dos program...?
    Any ideas very very welcome. I've reached hair pulling out time!
    Ben Barker

    I can see a couple of ways to do this.
    1. Using - as you suggested - exec and input stream/output stream.
    I suggest you write a really tiny java control program to test this. You can simply never tell what kind of input or output assumptions are built into the C code. (What I mean is, sometimes it is very hard to find somethng in the output you can use to control your java-sideparsing.
    2. An alternative is to turn the C code into a shared library (dll or so) with an appropriate Native interface and java object with methods declared "native". It sounds like your fundamental model is java calling C code, so if the interface only requires a few calls, then this could work well.

  • Running DOS program from java

    Hi all,
    I'm trying to execute a dos program using:
    runtime.exec("dos_prog.exe")
    THE PROBLEM : in this way I can run only
    WINDOWS programs and NOT DOS progs.
    What to do ???

    Hi all!
    I'm tring to run a file.bat that execute an exp from locale Oracle server. But when I run it, in dos consol it appaire just only the EXP USER/PASS ....., and don't execute never!! Really, the files of .dmp and of .log, they are created, ...but empty!!!! Why???
    ........ source .......
    Runtime rt = Runtime.getRuntime();
    Process rtProcess = rt.exec("cmd.exe /C file.bat");
    // wait for command to terminate
    try      {
         rtProcess.waitFor();
    catch     (InterruptedException ire)
         System.err.println("Thread interrupted " + ire.getMessage());
    // check its exit value
    if (rtProcess.exitValue() != 0)
    System.err.println("exit value was non-zero");
    // close stream
    bReader.close();
    ........ file.bat .......
    @echo off
    EXP USER/PSW FILE=EXPFILE.DMP LOG=FILELOG.LOG OWNER=MYOWNER
    If you want, you car reply me directly at [email protected] - Thanks very much!!!

  • Controlling a C program from Java

    I'm developing a Cross Correlation Spectrum Analyser designed around a PCI ADC card. I've written some C code, which interfaces with the card, captures the data and performs the relevant signal processing. I've also written a Java front end that allows the user to input the parameters for the card, and plots the resultant spectrum.
    What's the best way to interface these two? The C program sits in a loop waiting for input parameters. When it has them, it performs the operation, then waits for more input parameters again. Is it possible to interface these with a Process object and using getInputStream() and getOutputStream() methods? Or is there a better way?
    Thanks in advance for any advice you can offer.
    Bert

    if you plan to make a C and a Java app communicate, you should look into Java Native Interface (JNI)

  • Can't execute a DOS program from a Java one

    Hi everyone !
    I'm a student, working as an apprentice in a company, and I have to make a program to execute faster some daily routine.
    Here's my problem : I'm trying to execute a DOS program (mkisofs.exe) whick takes numerous arguments and enables me to create an ISO file.
    But, for now, I can't manage to make it work. I've used both Process and ProcessBuilder, but in vain (I'm a student, and not really a JavaProgrammingStar).
    If I would manually execute the command, I'll have to type under DOS the following command :
    "C:\Documents and Settings\myName\Desktop\Current\Local\mkisofs.exe"   -r -J -l -L -b "isolinux/isolinux.bin" -c "isolinux/isolinux.cat" -no-emul-boot -boot-load-size 4 -boot-info -table -graft-points -o D:\ISO\toto.iso "C:\Documents and Settings\myName\Desktop\Current\Local\Clonezilla"or (without spaces)
    C:\docume~1\myName\Desktop\Current\Local\mkisofs.exe   -r -J -l -L -b "isolinux/isolinux.bin" -c "isolinux/isolinux.cat" -no-emul-boot -boot-load-size 4 -boot-info -table -graft-points -o D:\ISO\toto.iso C:\docume~1\myName\Desktop\Current\Local\ClonezillaTill now, I've only managed to execute windowed program such as MsPaint.exe or DOS program from System32 directory such as taskkill.exe, but I couldn't execute, for example, tasklist.exe, or at least, I couldn't see the result of this command.
    Can anyone help me ?
    If some code is needed, jsut tell me.
    Thanks by advance !
    Hubert

    Ok guys, I'm French, so excuse me if I didn't use the correct terminology, but I'm quite sure you understood that I was talking about MS-DOS command prompt in Windows XP.
    Then, of course I've STFW, but none on my tries was successful. So a little help would be appreciated.
    I've first tried this :
    ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/K", "mspaint.exe");
                      pb.redirectErrorStream(true);
                      try {
                          Process p = pb.start();
                          BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                          try {
                              String rep = in.readLine();
                              System.out.println(rep);
                          } finally {
                              in.close();
                      } catch (IOException e) {
                          e.printStackTrace();//repTF.setText("erreur");
                      }It worked.
    But this :
    String CMD = "C:\\docume~1\\myName\\Bureau\\Current\\Local\\mkisofs.exe";
    String arg1 = "-r -J -l -L -b \"isolinux/isolinux.bin\" -c \"isolinux/isolinux.cat\" -no-emul-boot -boot-load-size 4";
    String arg2 = "-boot-info -table -graft-points -o D:\\ISO\\toto.iso C:\\docume~1\\myName\\Bureau\\Current\\Local\\Clonezilla";
    ProcessBuilder pb = new ProcessBuilder(CMD, arg1, arg2);
                      pb.redirectErrorStream(true);
                      try {
                          Process p = pb.start();
                          BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                          try {
                              String rep = in.readLine();
                              System.out.println(rep);
                          } finally {
                              in.close();
                      } catch (IOException e) {
                          e.printStackTrace();//repTF.setText("erreur");
                      }does'nt.
    What's wrong ? I should use a String table for args ?

  • How to invoke dos shell from java program

    Hi,
    I'm not able to invoke dos shell from java.
    Can any one help me in this issue.
    I'm providing the source code below:
    try{
    Runtime.getRuntime().exec("cmd.exe")
    catch(IOException e) {
    System.out.println(e.getStackTrace());
    Thanks

    Does it throw a different exception?
    Or does it just do nothing at all?
    It does nothing at all[/b
    Is this a standalone Java app?
    Or a Java Applet running via a webbrowser? [b]It's a standalone application

  • Can we run EXE file/ Another Java Program from Java Application? How?

    Can we run EXE file and another java program from java application?
    Thanks in advance

    Example running adobe acrobat
    String command = "C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe /t "+selectedDocument+" \\\\CONTROL\\HP LaserJet 4L";
    Runtime rn = Runtime.getRuntime();
    Process process = rn.exec(command);
    process.waitFor();rykk

  • How do I call a C++ program from Java?

    I've tried using Runtime.exec to call my C++ program from Java but I don't think I'm doing it correctly. Could someone explain how to properly use it? Here's what I'm trying (this is in an applet that is only going to be running on an intranet so only PCs in my LAN will be affected):
    Runtime runtime=runtime.getRuntime();
    Process proc =runtime.exec("mkdir C:\\Test");

    What do you expect your operating system should do with a command "mkdir"? It doesn't understand this. "mkdir" is a shell command, so you need to execute the shell:
    runtime.exec("cmd /c mkdir C:\\test");

  • How to Call abap functn/program from java layer

    Hi all,
        I have to develop a program which has to call abap function/program from java side or how to call a abap program through java ..
    pls send me related links or explanations.. dont send unrelated answers..
    Regards,
    Arivarasu S

    Hi,
    You mean accessing ABAP functions from J2EE perspective, then I think we can do this by using SAP Java Resource Adapter and also through webservices.
    SAP Java Resource Adapter (SAP JRA) can be used as an add-on for the SAP JCo SAP JRA enables the implementation of standard interfaces from diverse J2EE servers to the SAP JCo in the SAP Web AS. The SAP JRA thus simplifies
    communication with ABAP within heterogeneous J2EE landscapes.
    Go through the following links which has Good documentation on how to achieve this
    Accessing BAPIs Using the SAP Java Resource Adapter
    [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/ad09cd07-0a01-0010-93a9-933e247d3ba4]
    Connectivity and Interoperability
    [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/326d82e5-0601-0010-fca4-9caf27b89c26]
    Finally with WebServices. Accessing SAP Business Functions (ABAP) via Web Services
    [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/06adbf03-0a01-0010-f386-d8e45561a3c4]
    Regards
    Raghu

  • Dos command from java

    hi all
    how do i run dos commands from java??????????

    Using Runtime#exec().
    Also see http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html

  • DOS command from java applet

    Hi, I need to perform a DOS command from Java (using WFC if needed)...
    I have no idea, so please help!
    Thank you.

    OH OH OH WAIT! It is an Applet! i think there will be some security issues here! Sure enough you can't execute commands on the system from an applet unless you make some changes on the java.policy files on the client machine (that means, if your applet is in a web page, every machine which view your page).

  • Error in calling 'C'  Program from Java

    Hi,
    We developed a 'C' Program and during compilation, we got a couple of Incompatible Prototype warnings. Then we made a Jni call to 'C' program from Java Program. The program returned a "Unsatisfied Link Error - unreference Symbol not found" error.
    Does Jni call fails owing to warnings by compiler?
    We are using Sun Solaris 2.8.
    Request your assistance as this a urgent issue.
    Thanks
    Srini

    Did you try running your C program through g++? It sounds like something is broken, but GCC often will allow you to compile anyways.
    -Jason Thomas.

  • Call visual prolog program from java

    Hi friends,
    is there someone help me to call ( run) prolog program from java.
    i write a parser with Javacc parser generator and stored parsed information in prolog database and I want create some query in java that work in the prolog file.
    how can i combine java and prolog programs. i used visual prolog.
    Can someone help me?
    Thanks you in advance.
    yours sincerely,
    ksu

    Since visual prolog can produce dll's, you can use JNI:
    http://java.sun.com/j2se/1.4.2/docs/guide/jni/index.html

  • Invoking dos commands from java

    hi all,
    I just want to invoke dos prompt from java.I know it can be done using "Runtime.getRuntime()" command.But when i try to create a directory inside another directory,how can i specify the path of the destination directory.i googled as well as tried different things.But i failed to make it up.Please help me solve this problem.
    thanks in advance
    Regards

    Hai,
    Thanks for your respond.
    If I give "cmd" command only, I am getting dos command window, but I didn't get the prompt like
    c: or d:
    How can I do it?
    Expecting more helps
    Joseph

  • Problem while running dos command from java program

    Dear friends,
    I need to terminate a running jar file from my java program which is running in the windows os.
    For that i have an dos command to find process id of java program and kill by using tskill command.
    Command to find process id is,
    wmic /output:ProcessList.txt process where "name='java.exe'" get commandline,processid
    This command gives the ProcessList.txt file and it contains the processid. I have to read this file to find the processid.
    when i execute this command in dos prompt, it gives the processid in the ProcessList.txt file. But when i execute the same command in java program it keeps running mode only.
    Code to run this command is,
    public class KillProcess {
         public static void main(String args[]) {
              KillProcess kProcess = new KillProcess();
              kProcess.getRunningProcess();
              kProcess = new KillProcess();
              kProcess.readProcessFile();
         public void getRunningProcess() {
              String cmd = "wmic /output:ProcessList.txt process where \"name='java.exe'\" get commandline,processid";
              try {
                   Runtime run = Runtime.getRuntime();
                   Process process = run.exec(cmd);
                   int i = process.waitFor();
                   String s = null;
                   if(i==0) {
                        BufferedReader stdInput = new BufferedReader(new
                               InputStreamReader(process.getInputStream()));
                        while ((s = stdInput.readLine()) != null) {
                         System.out.println("--> "+s);
                   } else {
                        BufferedReader stdError = new BufferedReader(new
                               InputStreamReader(process.getErrorStream()));
                        while ((s = stdError.readLine()) != null) {
                         System.out.println("====> "+ s);
                   System.out.println("Running process End....");
              } catch(Exception e) {
                   e.printStackTrace();
         public String readProcessFile() {
              System.out.println("Read Process File...");
              File file = null;
              FileInputStream fis = null;
              BufferedReader br = null;
              String pixieLoc = "";
              try {
                   file = new File("ProcessList.txt");
                   if (file.exists() && file.length() > 0) {
                        fis = new FileInputStream(file);
                        br = new BufferedReader(new InputStreamReader(fis, "UTF-16"));
                        String line;
                        while((line = br.readLine()) != null)  {
                             System.out.println(line);
                   } else {
                        System.out.println("No such file");
              } catch (Exception e) {
                   e.printStackTrace();
              return pixieLoc;
    }     when i remove the process.waitFor(), then while reading the ProcessList.txt file, it says "No such file".
    if i give process.waitFor(), then it's in running mode and program is not completed.
    Colud anyone please tell me how to handle this situation?
    or Is there anyother way to kill the one running process in windows from java program?
    Thanks in advance,
    Sathish

    Hi masijade,
    The modified code is,
    class StreamGobbler extends Thread
        InputStream is;
        String type;
        StreamGobbler(InputStream is, String type)
            this.is = is;
            this.type = type;
        public void run()
            try
                InputStreamReader isr = new InputStreamReader(is, "UTF-16");
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                    System.out.println(type + ">" + line);
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
    public class GoodWindowsExec
        public static void main(String args[])
            try
                String osName = System.getProperty("os.name" );
                String[] cmd = new String[3];
                 if( osName.equals( "Windows 95" ) )
                    cmd[0] = "command.com" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                } else {
                    cmd[0] = "cmd.exe" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing " + cmd[0] + " " + cmd[1]
                                   + " " + cmd[2]);
                Process proc = rt.exec(cmd);
                System.out.println("Executing.......");
                // any error message?
                StreamGobbler errorGobbler = new
                    StreamGobbler(proc.getErrorStream(), "ERROR");           
                          // any output?
              StreamGobbler outputGobbler = new
                    StreamGobbler(proc.getInputStream(), "OUTPUT");
                          // kick them off
                errorGobbler.start();
                outputGobbler.start();
                // any error???
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
            } catch (Throwable t)
                t.printStackTrace();
    }when i execute the above code, i got output as,
    Execing cmd.exe /C wmic process where "name='java.exe'" get commandline,processid
    and keeps in running mode only.
    If i execute the same command in dos prompt,
    CommandLine
    ProcessId
    java -classpath ./../lib/StartApp.jar;./../lib; com.abc.middle.startapp.StartAPP  2468
    If i modify the command as,
    cmd.exe /C wmic process where "name='java.exe'" get commandline,processid  > 123.txt
    and keeps in running mode only.
    If i open the file when program in running mode, no contents in that file.
    If i terminte the program and if i open the file, then i find the processid in that file.
    Can you help me to solve this issue?

Maybe you are looking for

  • Client Side Signature of PDF in HTML Viewer returning the chnaged/signed PDF.

    Hi, I am generating a SFP PDF form which I then immediately save to a SAP PSRM Case.  I generate the PDF form 'fillable' and I have inserted a Signature Field in the form layout. I have a requirement to save the signed form to the case once it has be

  • Document Server Technical Details - BMP storage

    Looking for someone with technical details to help me bridge a time gap on how logo uploads are actually stored.  I'm trying to find a workaround to display a jpg instead of a bmp (even if it's stored in a file server, not document server).

  • How  to find the current item is new

    I create a item ,and diaplay "new" .so I want to know which table I can find the "new" identifier. if anyone konw this please contract me .my Email :[email protected]

  • EJB container caught java.lang.NoClassDefFoundError package/classname

    Hello, If i start the Websphere 5.1 Test Environment with my EAR deployed in it the following Error appears: EJB container caught java.lang.NoClassDefFoundError: package/class      at java.lang.Class.getDeclaredMethods0(Native Method)      at java.la

  • How to restore iOS 6.1.3 on iPhone 4S

    I am stuck with my iPhone 4S in recovery mode. I upgraded to iOS7, some how it did not work well for me, so I tried to downgrade to iOS 6.1.3. The downgrade failed. Now I am stuk with recovery mode. I am not even able to restore my iPhone to factory