5 Replies Latest reply: Nov 29, 2008 10:09 AM by 807589 RSS

    Invoking EXE file with parameters -Problem

    807589
      Hello Everyone
      I have a peculiar problem here .I am invoking a exe file written in C and the C program creates a file and saves the input parameter given through the java program and the exe file also returns a integer value .

      The problem is the java program is invoking the exe file and getting the return value and printing it .But the file isn't created .I have copy pasted the code below .Please take a look at it and try helping me ..

      The java program is coming below

      package mfrp.project;
      import java.io.IOException;
      public class ExeInvoke {
           
           public static void main(String[] args) throws IOException, InterruptedException {
                int exitVal ;
                String arg[]={"C:\\Dev-Cpp\\MFRP.exe","HelloFile"};
                Runtime runtime = Runtime.getRuntime();
                Process process = runtime.exec(arg);
           process.waitFor();
           exitVal =process.exitValue();
           System.out.println("EXE has been executed and the Exit Value is :"+exitVal);
           }
      }
      I have also copy pasted a simple version of the c program that accepts the I/P parameters and creates a text file .

      #include<stdio.h>
      int main(int argc, char *argv[] )
      {   FILE *f1;
      f1=fopen("ESQL Output.txt","w");
      fprintf(f1,"%s",argv[1]);
      //fprintf(f1,"hello there");
      fclose(f1);
      return 456;
      }
      The exe file created is located in c:/Dev-Cpp/MFRP.exe
      And the command line argument that I provide is MFRP.exe <String withoutspaces>


      The problem here is the java program is printing the exitVal ie 456 .But I dont see any file created in c://Dev-Cpp// .
      But when I invoke the exe file from command prompt the text file is created .