This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Java Runtime.exec()


Hi,

>From the description of your problem, it is that you are unable to run a
shell script (ie, a file that starts '#!/....some interpreter').  This
is due to the fact that this file format is not understood by Windows,
and Cygwin has to do some interpretation of the file to make it work.
The JVM is not using the Cygwin exec functions.  There are a few
possible solutions, depending on how well you need the function to
perform.

If you know what the interpreter of your script is, you can just call
Runtime.exec("<path to interpreter> <script filename>"), which should
work.

Alternatively, If you do not know what the type of file is you could
load the first line of text out of it, and if it starts #! translate the
rest of the first line to a windows filename (in most cases just
prepending the path to the cygwin root directory should suffice) and
exec that.

A third option, if you want to spend the time on it, would be to write a
CygwinRuntime java class (or similar) that interfaced directly to the
cygwin library.  This could include functions for translating filenames,
executing programs, etc, and would be a generally useful class to have
around.

Jules




Hi,

We are using cygwin to run our application. I am trying to execute a shell
file at the operation system through java. The code is as follows 


     String unixCommand = "./run.sh";
     Runtime rt = Runtime.getRuntime(); 
     Process proc = rt.exec("unixCommand"); 

     InputStream result = proc.getInputStream(); 
     InputStreamReader isr = new InputStreamReader(result); 
     BufferedReader br = new BufferedReader(isr); 
     String line = null; 
       
     while ( (line = br.readLine()) != null) 
             out.println(line); 
       
     int exitVal = proc.waitFor(); 


  I am getting CreateProcess Exception when I try to run this code. It does
work well for other unix commands like "ls" or "ps". Am I doing something
wrong?


Regards

Sachin 



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]