Running external programs

hey
I have a very simple C program that writes a small amount of data to a text file.
Im trying to get my main Java program to run this C program regularly (in a loop, with lots of other java operations) ..
is this possible from within a java program? Ideally, it would run the C program and wait for it to finish, then
carry on with the code in the loop.... then obviously do this again each iteration. Ive written all the code
but now i just need to get this C program to get executed!
thanks for any help!

You could use the method ,
String commandtorunexe = "C:\myprogram.exe";
Runtime.getRuntime().exec(commandtorunexe);

Similar Messages

  • Running external program using java

    hi
    i am trying to run an external program using the runtime.exec() method. my problem is that the external program only runs when i press ctrl-c to exit my program. does anyone know how i can execute the external program while my program is still running without having to quit the program?should i be using threads?
    thanks

    As per the api doc exec will be executed as a seperate process
    Process exec(String command) ------Executes the specified string command in a separate process.
    Can you able to share that code what you have written ?

  • AIR 2.6: Run external programs sequential (1 by 1)?

    Hi,
    I managed to run an external program in Adobe AIR (2.6). I'm using the NativeProcess for this. I would like to perform the following actions.
    Pseudo-code:
    execute program.exe
    this will return a port number
    set the port number as an environment variable (in windows)
    execute program.exe with several queries
    stop progam.exe
    The corresponding executables:
    C:\my_proj\program.exe start
    var portnumber:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
    C:\WINDOWS\system32\cmd /c set port=portnumber
    C:\my_proj\program.exe query test1
    C:\my_proj\program.exe query test2
    C:\my_proj\program.exe stop
    My problem is the bold text in my source code underneath. I'm trying to wait till the first native process is finished and had returned its output. Once I have this output (=the portnumber) I can continue with the following action. And this is needed for all steps ... to execute them one by one.
    But "do {} while (process.running);" is not working. My AIR applications is getting stuck in this loop ... as if process.running is always true.
    Any idea how I can execute external programs sequential?
    This is my source code:
                var file:File = File.applicationDirectory;
                file = file.resolvePath("NativeApps");
                if (Capabilities.os.toLowerCase().indexOf("win") > -1)
                    file = file.resolvePath("C:\\my_proj\\program.exe");
                var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                nativeProcessStartupInfo.executable = file;
                var processArgs:Vector.<String> = new Vector.<String>();
                processArgs[0] = "start";
                nativeProcessStartupInfo.arguments = processArgs;
                nativeProcessStartupInfo.workingDirectory = File.documentsDirectory;
                var process:NativeProcess = new NativeProcess();
                process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
                process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
                process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
                process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
                process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
                process.start(nativeProcessStartupInfo);
                do {} while (process.running);
                file = file.resolvePath("NativeApps");
                file = file.resolvePath("C:\\WINDOWS\system32\\cmd");
                var nativeProcessStartupInfo2:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                nativeProcessStartupInfo2.executable = file;
                processArgs[0] = "/c";
                processArgs[1] = "set";
                processArgs[2] = "port="+portnumber;
    public function onOutputData(event:ProgressEvent):void
                var process:NativeProcess = event.target as NativeProcess;
                var portnumber:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
    public function onExit(event:NativeProcessExitEvent):void
                process.exit();

    Hello,
    The  "do {} while (process.running);" may take almost all of the resource, so other code was blocked, then the program seems no response.
    You can add the following code in the onOutputData, like:
    public function onOutputData(event:ProgressEvent):void
        var process:NativeProcess = event.target as NativeProcess;
        var portnumber:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvail able);
        file = file.resolvePath("NativeApps");
        file = file.resolvePath("C:\\WINDOWS\system32\\cmd");
        var nativeProcessStartupInfo2:NativeProcessStartupInfo = new NativeProcessStartupInfo();
        nativeProcessStartupInfo2.executable = file;
        processArgs[0] = "/c";
        processArgs[1] = "set";
        processArgs[2] = "port="+portnumber;

  • Run external programs using runtime class

    Okay, I'm experiencing a really annoying problem with java.lang.runtime
    I'm building a GUI that needs to run some external programs, via a button say. These generally produce a text file or something, so I don't need to stream the output or anything (at least I'm assuming I don't?). Should be very simple...
    So at the terminal (bash) I would type ./programName , and everything will run hunkey dorey.
    In my code then, natrurally, I write
    String cmd = "./programName";
    Process p = runtime.getRuntime().exec(cmd);
    But low and behold...nothing happens. What is going on here, and how do I get around it! ??
    (On windows incidentally, it's no problem at all and works absolutely fine. But when I go over to mac, which is what I need to use, I'm screwed - only adding to the annoyance!)
    Any help would be much appreciated as I have a deadline looming!!

    You need to read the 4 sections of [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html] and implement the recommendations. Failure to implement all the recommendations will cause you grief.
    P.S. The fragment of code you have posted shows that you have fallen for at least 4 of the traps.

  • Running External Program

    Hi All
    I really hope that some one can help ,e with my problem as i have no idea. OK i am calling an external program that outputs documents. This program uses control files and for each job there are 5 control files. Thus i call this program 5 times to get all my output documents. When i run this program from the command line then it works fine, however when i call it from my code i can see that it is working because my outputs are processed and i can see the program in the task manager. But it stops and does not continue to the next call, its like after this program does the processing then it just hangs. I dont know what is wrong and i cant get any errors in the logs either. I think that the problem either is with my java instalation as i had problems on the server and had to re-install java because someone installed multiple versions or that it is a jvm problem. Can some one please give some ideas of what could be the problem. My code looks as follow:
    Process p = Runtime.getRuntime().exec("d://cep//nt_engine_010_62 prodengine -controlfile=d://cep//document1.txt");
    p.waitFor();
    System.out.println(p.exitValue());

    You may want to give this code a try:
    ProcessBuilder pb = new ProcessBuilder( whatever_command );
          pb.redirectErrorStream();
          Process p = pb.start();
          InputStream is = p.getInputStream();
          BufferedReader br= new BufferedReader( new InputStreamReader( is ) );
          for ( String line = br.readLine(); line != null; line = br.readLine() )
            System.out.println( line );
          p.waitFor();

  • Run external programs

    Hi there..
    I need a example to run others programs from Java, for example lunch the explorer.. Is possible do that?
    Thanks you

    Have a look at the Runtime class and especially the exec method. You should be able to do what you want using the following code:
    Runtime.getRuntime().exec("explorer");

  • Running external program from Form6i

    I have a Form 6i, client server application and from there I launch a window based help system, using Host command.
    Is it possible to run both the form application and the help program togather at the same time. As at the moment I need to close the help program to start using my Form based application.
    Regards
    EVA

    Hi,
    I had a similar query and got the following reply and it looks better. Attaching it for ur reference and hope it will help u.
    Thx.
    R. Magesh.
    Magesh
    unregistered posted May 15, 2001 08:25 AM
    Hi,
    Thx. for ur reply but I am already using the same host command and it is working fine. But we do have some problems in using the host command like u need to close the external application or o/s based application before working back in forms and also that I would like to use a generic html tag which can be opened in any default browser defined for the system rather than mentioning or invoking explorer explicitly. I am looking for any new builtin available in FORMS6I which can support web integration with the application.
    Thx.
    R. Magesh
    quote:
    Originally posted by Fan Liu ([email protected]):
    try this:
    http:
    host('explorer http://www.oracle.com');
    email:
    host('explorer mailto:[email protected]');
    IP: Logged
    Duncan Mills ([email protected])
    unregistered posted May 15, 2001 09:14 AM
    If you want to start a Host type command Asynchronously then you can use DDE.APP_BEGIN or the WinExec call in the D2KWUTIL library.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Eva Maria Villoria ([email protected]):
    I have a Form 6i, client server application and from there I launch a window based help system, using Host command.
    Is it possible to run both the form application and the help program togather at the same time. As at the moment I need to close the help program to start using my Form based application.
    Regards
    EVA <HR></BLOCKQUOTE>
    null

  • Help with running external programs within java

    Hi,
    I'm new here, and not sure whether i'm in the right place for this, but i thought i'd give it a shot anyway!
    Basically i have a fortran program already written, that takes in the name of a text file as an input. I'm wanting to create a user interface to create this text file, and then i would have a button or something to enable me to then run the fortran program and input the file all from the user interface, and get rid of the need to manually run the fortran program.
    Firstly, is this even possible?! Is it difficult to program and get to work?! Does anyone have any suggestions or guidance on this.
    Thanks

    @Op.
    ..and here are two links related to that.
    http://java.sun.com/developer/JDCTechTips/2003/tt0304.html
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Run external program

    hello, i have found a font selection program here
    http://www.akgupta.com/Java/ColorChooser.htm
    and i want to add it to my program!
    i have made an action listener but i dont know how to call the font selection program to run!!
    could you please help me?
    thanks!

    sorry if i am being vexing, i dont know much about java and i would appreciate some help!
    i saw the main
    public static void main(String[] args) {
        final JFrame f = new JFrame("FontChooser Startup");
        final FontChooser2 fc = new FontChooser2(f);
        final Container cp = f.getContentPane();
        cp.setLayout(new GridLayout(0, 1)); // one vertical column
        JButton theButton = new JButton("Change font");
        cp.add(theButton);
        final JLabel theLabel = new JLabel("Choose Your Font!", JLabel.CENTER);
        cp.add(theLabel);
        // Now that theButton and theLabel are ready, make the action listener
        theButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fc.setVisible(true);
            Font myNewFont = fc.getSelectedFont();
            System.out.println("You chose " + myNewFont);
            theLabel.setFont(myNewFont);
            f.pack(); // adjust for new size
            fc.dispose();
        f.setSize(150, 100);
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }f.setVisible(true); is the frame but i cant access it from the other class!

  • Run External Program/installer

    Does anyone know how to make a button in flash that when
    clicked will run a given program, which in my case will be 3
    buttons assigned to 3 different program install exe files. The same
    sort of thing as what runs when you install the macromedia
    programs.
    Thanks!
    -Austin

    Yes you can read this
    http://www.flashjester.com/?section=faq&cPath=28_41#202
    Regards
    FlashJester Support Team
    e. - [email protected]
    w. -
    http://www.flashjester.com
    There is a very fine line between "hobby" and
    "mental illness."

  • Problems running external programs from java

    Hello.
    I wrote a pair of perl scripts and a GUI in java to run them. The first perl script just read the files in one directory makes some changes to the names of the files and then group all this files in a set of new directories. The other perl scripts takes all this new files and calls BLAST sequence alignment program and perform some alignments among these sequences. I tested this scripts and they work fine.
    The problem comes when I try to run them for the JAVA GUI. I use RunTime and when I need to run the first perl script it all works well, but when The call to the second perl script is made the program fisishes without doing anything at all. I found out that the problem is that when running the script from the Java GUI it's not able to find BLAST program. So I guess that Java is not really starting a terminal session and it doesn't read my bash_profile to find out the path to my programs.
    So, my question is if anyone knows a method to tell Java to load all this paths in the bash_proflie file so all of my scripts work???.
    I have no idea is this can be done and how so any advice would be really wellcome.
    By the way, my java version is 1.4.2 and my OS is Mac OS X 10.3
    Thanks a lot , Julio

    Invoke /bin/sh -c and give it your program's full path with.
    (To understand what I've written, maybe reading
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html
    http://mindprod.com/jgloss/exec.html
    and
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    (especially the exec(String[] cmdarray) method)
    might help)
    -T-

  • Run External Program in Java

    I need to run a VB batch in a class Java.
    If someone can help me because I don't know the method.

    It's OK but if I don't export the result on the standard output, the run doesn't work.
    So I added this code :
    DataInputStream dis = new DataInputStream( newProcess.getInputStream() );
    String line;
    while( (line = dis.readLine()) != null )
    System.out.println(line);
    Have you got another solution to do it or an explication on this ?
    Thanks

  • Running External Program From Flash

    Is it possible to open Windows calculator (calc.exe) from
    Flash much like the JumpOutReturn function in Authorware? My
    apologies if this seems like a simple routine.

    I'm rather new to Flash myself so I can't say whether Flash
    offers the ability to "open" a 3rd party application -- but
    considering what I've read I would venture to say the answer is
    "no". However, if you create (or use) a simple server, you could
    use Flash Sockets or XMLSocket to communicate with the server and
    have the server launch the application on your behalf.

  • Running an External Program from Batch on Windows Server 2008R2 Failing

    Hi,
    I am trying to run an external program from a batch job and it is failing with this error message:
    Ext. prog.: ERROR: Input redirection is not supported, exiting the process immediately.
    Ext. prog.: External program terminated with exit code 1
    The program I am trying to run is:  timeout
    This command works on the OS: timeout -t 30
    I have setup the step to look like this:
    Under External Program:
    -Name: timeout
    -Parameter: -t 30
    I have also tried:
    -Name: timeout -t -30
    -Parameter:
    I am running ECC 6.04 on top of Windows Server 2008R2 with SQL Server 2008R2. 
    When we were running in Server 2003 on ECC 6.0 I was able to use the Sleep program just fine in the same manner.  I have found out that sleep is not available in server 2008.  It was replaced with timeout.
    After an update to EHP4 and moving to Windows Server 2008R2, Is there any pre-work that needs to be done on the SAP or Windows side before we can run external programs?
    Thank you,
    Neil

    > SAPService<SID> and <SID>ADM both have Administrator rights for the server.
    > That means they should have full access.
    No - this is no more true like that since Windows 2008, it's a bit more complex:
    http://en.wikipedia.org/wiki/User_Account_Control
    > Where would you setup the permission/policy to "interact with the desktop"?
    Add the policy using group policy editor (gpedit.msc)
    Markus

  • Run external exe program from APEX button

    Hi,
    I want to run external programs like EXCEL or Word called from an APEX button.
    Does anyone hav an idea?
    Regards,
    Siegwin

    Hi Siegwin,
    To my knowledge, there are two possibilities running apps on the client side: Either user IE with ActiveX or create your own browser and deploy it with the application.
    I did this using the WebKit browser which comes free with the Qute-Framework. It works very well, the only thing I need to do is create a link that starts with os:// to start an external application and hand parameters over. The browser is a minimal browser component, strong enough to run Flash and enabled to interact with the local computer. Deployment of this C++ application is a simple copy to a network device. This approach gave me piece of mind in regard to compatibility issues as well. The browser is a simple window that even don't allow for direct address entering, therefore the Apex-application looks like a normal application then and is unable to connect to any other internet resource other than the APEX applicaiton itself.
    To the others moaning about this security whole: There are situations where you need something like this, fi in intranet environments where you want to enable APEX to interact with the local environment. So I think it's a valid request.
    Best regards,
    Jürgen

Maybe you are looking for

  • JE Tax Group

    Hi In the Tax group I have C1, P1 and S1. This is the order as it display in Administration > Setup > Financial > Tax > Tax Group. I have defaulted tax group in G/L Account  Inventry to P1 ( Chart of Accounts >   Assests > Inventry > Account Details

  • How to do pdf form from doc in Formscentral

    Hi, I would like to know how to make pdf form in formscentral with doc file

  • Helped, how to load xml data into database

    Hi, Given a DTD, can the XML SQL Utility generate the database schema? I currently have the dtd file to define the data type and xml data and I am looking for ways of how the XML/DTD can be loaded into the oracle db. Any suggestions/recommendations a

  • Transferring data from one version of Photoshop to a newer version

    How do I transfer picture albums and face reco from Photoshop 9 to the new version12. When I insatlled 12 and added pictures they were installed without the album setup or the facial ID's.

  • Difference​s between compilatio​ns

    I have been struggling to find a solution for a interesting problem concerning the compilation of Labview. I might get different results when compiling the same program. Two problematic issues have come up. -Program can't connect to FieldPoint in any