Running an Executable from a JAVA API in LINUX
Hi,
I want to run a C++ executable from my JAVA API in Linux. This is the sample of the code which i
have used
String[] arguments = new String[5] ;
arguments[0] = "/usr/local/code/fun/dcmdump";
arguments[1] = "+f";
arguments[2] = "/usr/local/code/fun/240.dcm";
arguments[3] = "+W";
arguments[4] = "/usr/local/code/fun";
Process p = Runtime.getRuntime().exec(arguments);
On running the test file, the program seems to hang there. dcmdump is the name of my c++ executable and arguments [1] - [4] are its inputs. dcmdump should accepts these inputs and dump the contents of the file 240.dcm into the path mentioned by the last argument.
But my program jst hangs. Is the the correct way to go about??
Any suggestions or ideas r welcome!!
Please let me know
Thanks
Dhaval
Hi
I did the following
String[] cmd ={"/bin/sh","-c","/usr/local/code/fun/dcmdump","+f","/usr/local/code/fun/240.dcm","+W","/usr/local/code/fun"};
Process p = Runtime.getRuntime().exec(cmd);
When i execute my application, i see the following output
[root@voltaire fun]# java TestRead2
$dcmtk: dcmdump v3.5.3 2004-05-27 $
dcmdump: Dump DICOM file and data set
usage: dcmdump [options] dcmfile-in...
parameters:
dcmfile-in DICOM input filename to be dumped
general options:
I try to write the arguments in the command line when i execute but still get the same output.
I dont think dcmdump is receving any arguements..
Executing /bin/sh does it mean you have to mention the arguements in the command in the same manner that i have the String[] cmd??
PLease let me know..
Also i have put a Buffered reader to capture the output of dcmdump but I dont think i have reached my application has reached thr as yet. The code i have written is
// put a BufferedReader on the output
InputStream inputstream = p.getInputStream();
InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
// read the output
String line;
while ((line = bufferedreader.readLine()) != null) {
System.out.println(line);
Please let me know your suggestions/ideas.
thanks
Similar Messages
-
How to run an executable from command-line
I'm learning how to use the Terminal and I got stuck in a silly thing (I suppose it is). How can I run an executable file from command-line in Terminal?
For example: I have a file named "Hello" in the folder /sample. If I use the ls command (ls sample), I can see the file Hello. Then I move to the directory (cd /sample) and try to run the file Hello (typing "Hello") but I got "command not found" message.
If I drag the Hello file from Finder to Terminal and hit Return, it runs perfectly. And if I type the full path to the file (even if I'm already inside its directory), it also runs.
So, my doubt is if there is any command to run an executable from command-line.
ThanksKJK555 wrote:
Hi VK:
Can you enlighten me on why it's neccessary to do the "./" thingy in OS X when in unix/linux
I never had to resort to doing that?
Kj
I took the trouble of reading *man bash* and it explains the issue. to add the current directory to PATH you need to add an empty path to PATH like this
PATH=$PATH::
you can add it to ~/.bash_profile so that it's executed automatically when you start bash. I suspect the linux system you are talking about had this set up by default or had it added to PATH in /etc/profile which defines PATH globally. -
Extracting specific detial about class from the JAVA API created by Javadoc
hi ,
Bacialy I need to get detials of all classes from the Java packages for my project. So i thought getting detials from the Java API document might be one way of doing it. If any one tell me some package or software which can get particulat text from the API document that will be great.
Thank you,
RajHi,
I think, much easier way would be to write a little doclet. That doclet would take the information you need directly from the Doclet API and generate by it a plain text with the content you wish (for instance, as an SQL script that loads everything into a certain database).
Obtaining this from the generated HTML documentation just adds one extra step (and a lot more complicated, by the way).
Also, you can avoid even writing a doclet.
There is a tool called DocFlex/Javadoc:
http://www.filigris.com/products/docflex_javadoc/
It is a template-driven doclet, which can be easily programmed to do the job. (However, a license will be needed).
Regards,
Leonid Rudy
http://www.docflex.com -
Pls Help:Running a C executable from my Java Code
I am trying to run a C/C++ executable a.out from my Java code but its not working pls help me out...Its very very important
I am writing a segment of the code pls point out if i am making any mistakes
public void itemStateChanged(ItemEvent a)
int i=c1.getSelectedIndex();
Runtime r=Runtime.getRuntime();
try
if(i==0);
if(i==1);
if(i==2);
if(i==3)
r.exec("./prog/a.out");
System.exit(0);
}catch(Exception e){}
}I am working in UNIX enviornmentBefore any other attempt read: [url http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]When Runtime.exec() won't.
-
Can I use SubPanels to display and run multiple executables from the same GUI?
I have two Labview executables that performs some A/D I/O, each using an independent USB-6008. I would like to run both of these executables from a single UI. Is this possible usin SubPanels? Or some other method?
I found KB regarding exe's and VI Server but can't seem to get the suggested workarounds implemented.
http://digital.ni.com/public.nsf/allkb/8545726A00272EB0862571DA005B896C?OpenDocument
I am using Labview2009
Thanks
Dan
Solved!
Go to Solution.DBerry wrote:
No, of course I am not sure yet. I have only begun testing this method.
Not sharing common hardware (separate USM-6008s).
Here is the whole picture:
I have developed a top-level VI that performs Daqmx IO using a single USB-6008. The top-level VI references a Project Daqmx Task that points to the desired 6008. I would like to create a single UI that uses this top-level VI to control twoUSB-6008s simultaneously. I thought I could build the top-level VI into 2 separate exes, where the only difference between the exes is the hardware it points to (one exe to each of the 6008s). But I have been unsuccessful at running these two exes within a single UI. I attempted use subpanels on a tab control to do this but I am unable to obtain a reference to the top-level vis once they have been built into an exe. I have also tried building a dll and exporting the top-level vi from the dll build but i can't seem to get that to work either. In both of these cases my Open VI reference function returns errors (Error 1445). I am aware of the changes in referencing VIs from within an exe/dll since LV8.2 - http://digital.ni.com/public.nsf/allkb/8545726A00272EB0862571DA005B896C
The link seems to suggest that I should be able to obtain a reference to the top-level vi within the dll but I can't get it to work.
So I then moved on to the above method (making all the subvis reentrant). I just haven't figured this all out yet.
If you have suggestions on other problems I may run into please share. I think I can eliminate my FGs but haven't gotten back to this yet.
Thanks
Dan
When I am designing apps of the type you described I have kept the ned goal in mind from the begining since of the issue you are mentioning. I also don't want to tell you to throw it all away and start over. So with that in mind I have been looking at your posts and only offering the least destrutive ideas first. With that in mind I would like to invite yo uto look at the code i posted in this thread (reply #18 has a zip).
That code shows how to realize un-dockable GUI regions but it passes the ref of the top level VI to a reentrant VI it instanciate for each undockable region. It may have enough hints and technique to give you some ideas that will work for you.
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
Error while creating user id from MDM JAVA API in 7.1 SP7
Hi,
We are trying to create user id in MDM 7.1 SP7 using JAVA API in SAP Portal. When trying to create user id, we are getting below error. If you have any solution please let us know.
com.sap.mdm.commands.CommandException: MDM repository data is out-of-date or is locked by another MDM Server. Refresh the data and try the operation again. If the error persists, contact the system administrator
Thanks,
Vinit PugaliyaURGENT** How to change OIM user password from outside OIM
-
Running curl command from a java program using Runtime.getRuntime.exec
for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
Any ideas on why this might be happening?thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
I am using 7.15 in my system.
Below is the code which errors out.
public int execCurlCmd(String command)
String s = null;
try {
// run the Unix "ps -ef" command
Process p = Runtime.getRuntime().exec(command);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
return(0);
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
return(-1);
} -
Fetch Document from workspace+java API+ObjectByPath.java compile error
Hi All,
(Hyo version: 11.1.1.3)
I was trying to export files imported into workspace. For testing purpose I imported P4S.pdf in 'Sample Content' folder.
While looking for various options I came across Java API for workspace.(See samples in C:\Hyperion\products\Foundation\workspace\SDK\samples\java)
I found a Java sample named "ObjectByPath.java". I complied (using JC.bat) and executed (with Execapi.bat) and came with this output:
C:\Hyperion\products\Foundation\workspace\SDK\bin>execapi ObjectByPath admin password localhost 6800 "Sample Content/P4S.pdf"
library not available, add it to your classpath: spf.jar
Path : Sample Content/P4S.pdf
Name : P4S.pdf
Path : /Sample Content/P4S.pdf
Mime Type: application/pdf
Class : com.sqribe.rm.DataObjectImpl
ObjectID : 0000013828cfc4b7-0000-a30d-7f000001
Unfortunately the object could not be exported. I checked the "ObjectByPath.java" file and I saw:
String path = args[4];
RMBase tObject = rep.getObjectByPath(path);
// tObject.toXML(System.out);
System.out.println("Path : " + path);
if (tObject instanceof BaseObject) {
BaseObject baseObj = (BaseObject) tObject;
System.out.println("Name : " + baseObj.getName());
System.out.println("Path : " + baseObj.getPath());
System.out.println("Mime Type: " + baseObj.getObjectType().getMimeType());
System.out.println( "Class : " + tObject.getClass().getName());
System.out.println( "ObjectID : " + tObject.getObjectID());
Note that the exported line is commented.
When I remove the comment and recomplile with JC.bat I get this error:
C:\Hyperion\products\Foundation\workspace\SDK\bin>jc ObjectByPath.java
ObjectByPath.java:32: unreported exception java.io.IOException; must be caught or declared to be thrown
tObject.toXML(System.out);
^
Note: ObjectByPath.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
Any idea how to resolve this issue.
Thanks,
AnkitIt says to add spf.jar to your classpath. Can you do a search on the file system for that file? If you find it add to your classpath.
By commenting that line out you just produced another, unrelated error.
Thanks
Nick -
Trouble running sample code from the java trails
I'm trying to run Sun's DocumentEventDemo available on the trails. I can get it to compile successfully but I get several errors when I try to run it. After compiling the source, this is what I get when I try to run it:
C:\listen>java -cp . DocumentEventDemo
Exception in thread "main" java.lang.NoClassDefFoundError: DocumentEventDemo (wr
ong name: events/DocumentEventDemo)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
The source is available from the java trails using the name DocumentEventDemo
Thanks
~Sklaveactually that is really helpful. My directories are most likely incorrect, but I'm coming to java from a c/c++ background and don't know how to make the directories correctly for the given package. I'll look that up and see what I get. In the meantime, if you or anyone else could follow up with a link or a quick explanation on packages and directories that'd be great too.
~Sklave -
Calling an executable from a java program
How can I call a compiled program from a java program. I have a fortran program, which I would like to call for execution from within my java program. My OS is linux.
Thanks,
AnNot quite sure in the case of fortran program, but one thing can be done, call ur fortran program from a batch (.bat file) and call this .bat file from java ;
try {
Process p = Runtime.getRuntime().exec("run.bat");
p.waitFor();
catch( Exception e ) {
} -
How to launch executable from a java program
In c++ we can use a function WinExec to execute exe from a c++ program.
Is there a way to launch executables using java program. Lets say I have one executable with name "myexecutable.exe" and a java program "myprogram.java". How can I launch "myexecutable.exe" from the java program.
Is there a way to do this in Java?
Vijay>>
class LoadExecutable
static void loadProcess()
Runtime r = Runtime.getRuntime();
Process p = r.exex("winword.exe");
public static void main(String args[])
loadProcess();
}Regards
- ManikantanBoth of these aren't good ideas - neither of them
deals with the input or output streams at all.
Everyone who's posted to this thread should read this.
None of you knows how to use Runtime.exec properly:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-t
aps.html
MOD
Thanks for the tips
-Regards
Manikantan -
How to run exe file from inside java
I wan to run an exe file from inside java code. How can I do it?
ThanksHi Oakam
This is very simple. Just go through the given code below
in place of FILEANDPATHNAME just give the exe's path and name
Note :- adding ".exe " is not necessary
public class exep
public static void main(String args[])
Runtime r = Runtime.getRuntime();
Process p = null;
try{
p = r.exec("FILEANDPATHNAME");
catch(Exception e)
Give ur feedback
Thanx
Ottran -
How to run jsp pages from webdynpro java
Hi experts
I want to run the jsp pages present in a webserver like tomcat or weblogic servers from webdynpro.Is there any way to run a jsp from webdynpro environment?
Thanks and regards
venkat kalyanhi Venkat,
Check out this threads. They might be helpful
Re: web dynpro jsp
Re: Opening a jsp from another server(Weblogic) from webdynpro running on WAS
Regards,
Gopi -
Run external executable from script
Hi,
it's possible launch an external executable (Es. .\smsclient.exe "3201234567" "SMSClient.exe Tested on %date% at %time%") from script .aef (not from CAD)?Hi Anthony,
i have developed a Java class how you said me. I receive the sms, if run application from Eclipse. But if I invoke this class from script .aef not operate. For an simply example i have also created an Notepad example but not open pop up with notepad but also in this case if I run application from Eclipse all correctly function.
Above there is my script and java source for Notepad example.
Have you any suggestion?
***************************************SCRIPT testNOTEPAD.AEF********************************
Start
Do
testpackage.Notepad AA = new testpackage.Notepad();
End
In console i read this output:
Begin Debugging C:\UCCX_Script_Esempi\TestNotepad.aef...
when i stop debug:
Done Debugging C:\UCCX_Script_Esempi\TestNotepad.aef.
but Nptepad.exe not running
*******************************************JAVA SOURCE ********************************************
package testpackage;
import java.io.*;
public class Notepad {
public static void Main(String args[]) {
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("notepad.exe");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
System.out.println(line);
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace(); -
Firefox won't let me run and executable from the website-it wants to save it
Looks like I lost all this information when I clicked to install the troubleshooter???
again-- problem is I deleted old Internet Explorer and tried to install I.E. 8. With Firefox, I can't click download and choose run. When I click download I can only save.
The saved download doesn't produce a file that works (it just tries to install I.E. , cleans off old files and restarts the PC OVER AND OVER.)
I would like the choice to RUN a file instead of saving but I can't find out how to get this option back.
I disabled all plugins, add ons, looked for possible limiting causes in Firefox to disable. STILL--I have NO CHOICE.
Maybe this plea for help won't fix my problem and I will have to REPAIR windows--hate to risk it--I would have to back everything up, etc.
Hopefully a simple answer to this question will solve my problem.
Thank you to all who consider my question. I appreciate your time.
LibbyHi--
Thanks for the response. I was sure I used to have the choice to '''run '''or '''save '''when I started using Firefox and somehow I lost it with one of my adjustments. Forgot how or what I did!
Before going back to Microsoft to try that I.E. program file again, I tried one more time to run it. That was the 5th time I tried to install I.E. from the saved file --and it worked!
However, after that I tried to download an executable file from malwarebytes--- with and without my Kaspersky internet security program on--- the file RAN automatically anyway instead of insisting on SAVING!
Maybe this was a microsoft issue?
I am relieved that all is settled. Always try things 3 or more times is the rule with computers, right?
But thanks for the tips--I may need them someday. Likewise the Safe mode w/ network support tip.
ALSO--The page you referred me to was one I hadn't found with my own searching--it was much much better than the others. I bookmarked it.
Thanks again...
Maybe you are looking for
-
Problem with asa 5505 routing,nating
i have the asa 5505 with asdm 6.4(5). my inside lan is 192.168.0.0/24. the outside of asa is connected on lan 10.13.74.0/24 and i need over lan 10.13.74.0/24 connect on lan 10.15.100.0/24. i puted nat rule on asa 5505 and acl rule and users from lan
-
How do I replay a FLV file with flvPlayback AS3
Hey Everyone. Pretty new to Flash and AS3- so I apologize in advance if my terminology is all wacked out. I've researched this topic for the better part of a day and cannot find my solution. I've got a .flv file uploaded on my server that plays jus
-
'error 2001' What does that mean?
I get the message 'error 2001' when updating Acrobat. Using MacBook Pro with IOS Mavericks. What does that mean? / Sawant P
-
How to set credit limit to customer?
the credit limit for customer- X is 200000/- if more than 2lacs dont allow sales to that customer ..how to set these rules? thanks in advance
-
After install SXDE 1/08 don't start
Hi! I have install SXDE 1/08, but after start system halt after GRUB window. When I select safe mode - system start ok.