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.

Similar Messages

  • 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();
    }

  • 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 ?

  • 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)

  • Using Runtime.getRuntime().exec(DOS Program) with Windows 2000.

    I am trying to spawn a DOS Program from within Java.
    On Win95/98/ME, I use
    Process     p = Runtime.getRuntime().exec("START /w command.com con /c myDOSProgram.exe");
    This works on these platforms. On Win 2000, I use
    Process     p = Runtime.getRuntime().exec("START /w cmd.exe con /c myDOSProgram.exe");
    It does not work at all.
    I have tried all combinations of using START, cmd.exe, con /c, etc.
    I can spawn a Windows App using
    Process     p = Runtime.getRuntime().exec("windows.exe");
    And it works fine.
    What does it take to spawn a DOS program from Java on the Windows 2000 op sys?

    Hi. I recently wrote a java GUI that calls a DOS program with mixed success. Here's the code I used to make the call:String osName = System.getProperty("os.name" );
    String[] cmd = new String[4];
    if( osName.equals( "Windows 2000" ) || osName.equals( "Windows NT" ) )
         cmd[0] = "cmd.exe";
         cmd[1] = "/C" ;
         cmd[2] = "VBDoc.exe";
         cmd[3] = fileName;
    else if( osName.equals( "Windows 95" ) || osName.equals( "Windows 98" ) )
         cmd[0] = "command.com" ;
         cmd[1] = "/C" ;
         cmd[2] = "VBDoc.exe";
         cmd[3] = fileName;
    else
         System.out.println(osName);
    Process proc = runtime.exec(cmd);Check out this article, it gives a good explanation of how to use the exec() call:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Hope this helps!

  • Why itunes 10.5 64 bit wont install on my 64bit hp probook ? when i run it my user account control asks me that do you want the following program from unknown purblisher to make changes on you on this computer?  program name :itunes 64setup.exe  purblishe

    why itunes 10.5 64 bit wont install on my 64bit hp probook ? when i run it my user account control asks me that do you want the following program from unknown purblisher to make changes on you on this computer?
    program name :itunes 64setup.exe
    purblisher:unknow
    file location: hard drive on this computer when i click yes nothing happens
    aditional ateps iv taken, uninstalled all itunes including quick time,banjour mobile updates ,everthing that has to do with apple products.went into window regestry and i dint find anything that has to do with apple in software bar
    restarted my laptop several times, put the setup on a External USB but still nothing happens ,blowsed all most all sites on goggle no where iv seen this problem ,pliz who can help?

    why itunes 10.5 64 bit wont install on my 64bit hp probook ? when i run it my user account control asks me that do you want the following program from unknown purblisher to make changes on you on this computer?
    program name :itunes 64setup.exe
    purblisher:unknow
    file location: hard drive on this computer when i click yes nothing happens
    aditional ateps iv taken, uninstalled all itunes including quick time,banjour mobile updates ,everthing that has to do with apple products.went into window regestry and i dint find anything that has to do with apple in software bar
    restarted my laptop several times, put the setup on a External USB but still nothing happens ,blowsed all most all sites on goggle no where iv seen this problem ,pliz who can help?

  • How to change slider control digital display precision from program

    I want to change slider control digital display precision from my Labview 2013 program. I can not find property that changes slider digital display format. 
    Solved!
    Go to Solution.

    rt clk the digital display>create>property node>format string
    you could also do the slide scale, if needed...
    from the front panel:rt clk properties>goto display format tab>goto drop down list and pick "digital display 0" and format

  • Running java program from DOS

    I have just installed JDK 5.0 (update 4) and have tried writing a small demo program. The .class module is created ok but when invoking java I get "Exception in thread "main" java.lang.NoClassDefFoundError. I am running java from a DOS batch file with one command of c:\progra~1\java\jdk15~1.0_0\java %1. A similar batch file is used to invoke javac which works.
    Any ideas what I'm doing wrong? Thanks.

    You can't run a Java program from DOS, in fact you can't even install a JRE under that old operating system as Java requires a 32 bit or 64 bit operating system architecture which DOS never offered.
    But on the off chance you mean a command prompt from Windows...
    Check your classpath, most likely you forgot to add the current directory to that.

  • After updating from "about firefox",there're always two version showing up in my control panel's program list.

    I think everytime firefox update itself, it doesn't clean the old version's register key so there're both two version showing up in the control panel's program list.
    When you uninstall the old version, the new one disappears too.

    Firefox can find plugins in several locations, but Firefox 21 changed the location of the "shared" plugin folder so older installers like the Microsoft Windows Media Plugin no longer drop the DLL file in the correct location.
    There apparently are two ways to address this:
    (1) Change a Firefox preference so that Firefox checks the old location. Here's how:
    (i) In a new tab, type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (ii) In the filter box, type or paste '''plugins''' and pause while the list is filtered
    (iii) Double-click '''plugins.load_appdir_plugins''' to switch its value from false to true.
    This will take effect after you restart Firefox.
    (2) Copy the plugins folder to the new location. Here's how on Win 7 64-bit:
    Open a Windows Explorer window to:
    C:\Program Files (x86)\Mozilla Firefox
    Right-click and copy the '''Plugins''' folder
    Double-click the '''browser''' folder to open it
    Right-click and paste
    Right-click the new copy of '''Plugins''' and rename it to '''plugins'''
    After restarting Firefox, the plugins in that folder should now be available.
    ''Edit: I suggest just doing #1.''

  • NEED HELP:reading output from ms-dos program (with exec)

    I'm trying to execute an ms-dos program using exec,
    and reading it's output.
    the program is running ,but, I can't see it's output.
    I've tried many variations of this code:
    Process p = Runtime.getRuntime().exec("file_name");
    try { p.waitFor();}
    catch(Exception e) {}
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while((line = input.readLine()) != null )
    please help mewith this - thanks, froy
    System.out.println(line);
    System.out.println(p.exitValue());

    try { p.waitFor();}This doesn't return until the exec process has finished running. So there is no stream for it to get anything from.

  • I am running Mac OS 10.6.7 I cannot run a java based program from the net when parental controls are set the error is The error is Load: class installer.CheckVersion 13. class not found  Help!

    I am running Mac OS 10.6.7 I cannot run a java based program from the net when parental controls are set the error is The error is Load: class installer.CheckVersion 13. class not found 

    Then, talk to the person running the lab.

  • 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

  • Run program from any directory on Linux

    Hi, I'm using a shell on a Sun computer to run a Java program.
    The program requires the user to specify the name of an output file and and then an input file, manipulates the text in the input file, and prints it to the output file.
    I would like to be able to run the program from any directory.
    An IOException occurs if the input file is not in the same directory as the directory where you run the program.
    If I have an input file which I want to manipulate in a different directory to where the actual program files are located (.java and .class), how do I specify that?
    Thanks

    When you execute a java program from a given directory, all relative file paths (i.e. foo.txt) are resolved using the current directory. You can most likely run the program from anywhere as long as you specify an absolute path to your files and have permissions to both read and write. I say most likely because you could be doing something incorrectly in your code.
    If you want to run a program from anywhere, it must be:
    1) on your PATH
    2) be able to find its classes
    An easy way to do that is write a small "wrapper" shell script and put that on your path.
    I guaruntee you that a wise combination of terms used in this reply to compse a search engine query will yield you a useful tutorial or example.

  • Problems printing to LPT1 from DOS programs in windows 7

    Hello
    I'm having problems connecting a Epson Lx-300 II to a computer (desktop) without parallel print port, the environment is:
    Windows 7 starter
    Epson printer Lx-300 II connected via usb adapter
    Old DOS program that just prints to LPT1 ports
    I have done the following: install the printer, print the test page, as the programs need the LPT1 I share the printer (short name Lx300), then I tried to connect to the lpt1 port via DOS command net use (net use lpt1: \\caja\Lx300) but it ask me a password,
    and no matter what password I give it return an error incorrect password.
    I've read that Microsoft blocked out this port for security reason, I've done this procedure many times with xp, 2000, milenium, it works fine, but this windows resist.
    I just don't know what else to do, I'll apreciate any help.
    M.A.M.

    Dos is not supported in Windows 7. You need to install DOS virtual servers such as DOS Box to run the program.Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”

Maybe you are looking for

  • Can't add music to my iPhone 6 after update

    when i connected my iphone to my imac today, it would not allow me to upload any music from itunes . im running 12.1 and it looked like it was updating my phone. i lost my whole library except music already purchased from itunes. any ideas why this i

  • Problem while uploading excel file to server

    Hello, I have created an excel file using OLE and saved it to local desktop. Then I use GUI_UPLOAD to upload the excel into SAP and attach it to mail. but while using Function GUI_UPLOAD I am getting dump for CNTL_ERROR. If I skip the process of exce

  • How to factory unlock an iphone 4s (to work in Greece)?

    Factory unlock for iphone 4s

  • How to type vertical text

    In numbers, I've merged cells vertically in hopes of typing a word vertically but I can't figure out how to do it.  It's probably an easy process but I can't figure it out. Thanks for the help.

  • :SYSTEM.LAST_FORM issue....

    Hi , I have written the following code in the "exit" menu item: BEGIN      IF :SYSTEM.LAST_FORM IS NULL           THEN                 UPDATE USER_CONNECTIONS SET DATES_OUT=TO_DATE(SYSDATE,'DD/MM/RRRR'),                                        TIMES_O