Calling C code (exe ) from Java program
Hi all,
kindly help in giving a solution for calling C code (exe ) from Java program, i will be very thank full to u if any body can help in sending a code example
bye
You might need to consume the io operations on the Process...
An excerpt from java.lang.Process:
All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (Process.getOutputStream(), Process.getInputStream(), Process.getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
Similar Messages
-
Does somebody know whether it is possible to run some program with extension EXE from JAVA program?
Yes sombody knows. Yes it's possible. Have a look at Runtime#exec.
-
Calling oracle SQL Loader from java program
Hi,
I want to insert data into oracle tables from a text files containing fixed length fields. I am using SQLLoader to achieve this. The requirement is to call the SQLLoader within the java program.
Does anyone know how to call SQL Loader from java program?
Thanks,
VarshaSimply "exec" the sqlldr program with the parameters you need to pass to it.
Runtime.exec (........)
Try to pass all parameters needed including the username and password, and use the option "silent" to avoid output, and the option "log" to have a log file of the modifications that sqlldr has done to the database. -
Calling a C-exe from java code
I have an executable in C which would be located on a server while my java code resides on many clients. I have to call and execute the C code on the server. For this I need to send some input to the C code and receive output back (as strings) to java on the client. (I cannot use JNI since C code should be available as shared libraries for this).
Would anybody be able to help me out how to go about doing this ?Hi there
Hm! have you thought of using RMI
By doing so you can create a server program
that calls the dll / exe
All you clients calls the server that in his/her turn calls the C program and fetches the output and sends it back to who ever made the call.
More info about the RMI can be found at
www.jguru.com
//Markus -
How to call a perl module from Java program.
Hi,
I create a simple java program as follows
class test{
public static void main(String args[])
{try {
Runtime r = Runtime.getRuntime();
r.exec("perl test.pl");
catch(Exception e)
{e.printStackTrace();}
and test.pl is located in the same directory as the java program. The program compiles but with no return as I execute it. I am not sure what is wrong.
Thanks,I think the wrong line is here; r.exec("perl test.pl");
Usually the JVM needs the full path.If the path for either the executable or the script was wrong then, given the code posted, it would not hang.
>
To automatticaly get the path (if the file is in the
class path) use
System.getProperty("java.class.path")
That gets paths(plural).
Try this:
r.exec("perl " +
System.getProperty("java.class.path") + "\test.pl");I am rather certain that that won't work on any standard operating system. -
Call c++ program .exe from java
Hello every body
i have a problem while calling Hello.exe from java
c++ code
#include "stdafx.h"
#include <iostream>
# include <string>
using namespace std;
int main(int argc, char *argv[])
int x;
cout<<"Just test ";
return 0;
}java code:
import java.io.IOException;
public class runtime{
public static void main(String[] args){
try
Process process = Runtime.getRuntime().exec("Hello.exe");
}catch (IOException e)
e.printStackTrace();
}it display nothing!!alexxzius wrote:
String line="";
BufferedReader input =
new BufferedReader
(new InputStreamReader(process.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
There is a danger of deadlock in this code. The OP should 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 ALL the recommendations. -
How to call a .bat file from java code?
How to call a .bat file from java code? and how can i pass parameters to that .bat file?
Thanks in advancethanks for ur reply
but still i am getting the same error.
I am trying to run a .bat file of together tool, my code looks like below
import java.lang.Runtime;
import java.lang.Process;
import java.io.File;
class SysCall{
public static void main(String args[]){
String cmd="D://Borland//Together6.2//bin//Together.bat -script:com.togethersoft.modules.qa.QA -metrics out:D://MySamples//Metrics// -fmt:html D://Borland//Together6.2//samples//java//CashSales//CashSales.tpr";
//String path="D://Borland//Together6.2//bin//Together.bat ";
Runtime r= Runtime.getRuntime(); //Declare the system call
try{
System.out.println("Before batch is called");
Process p=r.exec(cmd);
System.out.println(" Exit value =" + p.exitValue());
System.out.println("After batch is called");
/*can produce errors which must be caught*/
catch(Exception e) {
e.printStackTrace();
System.out.println (e.toString());
I am getting the below exception
Before batch is called
java.lang.IllegalThreadStateException: process has not exited
at java.lang.Win32Process.exitValue(Native Method)
at SysCall.main(SysCall.java:17)
java.lang.IllegalThreadStateException: process has not exited -
How to call windows help files .hlp from Java program
Hai all everybody
How to call windows Help file that is xxx.hlp files from java programs
any help great!!!!
regards
veeruHow about
Runtime.getRuntime().exec("start xxx.hlp"); -
The following code will open 'Notepad'
Runtime runt = Runtime.getRuntime();
Process pr = runt.exec( "notepad" );likewise, I want to open 'Wordpad'
Runtime runt = Runtime.getRuntime();
Process pr = runt.exec( "wordpad" );The above two line code, compiles successfully, but it doesn't give the correct result.
If I give 'wordpad' in start->run->'wordpad', in windowXP means, the Runtime executer opens 'WordPad',
can anyone give the solution to open WordPad from Java Programming.
thanks
Sarwan_GresTry this:
Runtime runt = Runtime.getRuntime();
Process pr = runt.exec("cmd /c start wordpad"); -
How to Call .XDO file From Java Program
Hi,
I have developed a report in using BI Publisher version 10.1.3.
I created the report and it only created XDO files. If I want to call XDO file from Java program how I can do that.
What are the APIs available to do that.
Thanks
-AshutoshHi,
the JavaAPI didn't work with the xdo-Files. But you can create a proxy stub for the Web Service API of BI Publisher which uses the xdo's in the repository.
regards
Rainer -
How to call SAP Webservice in standalone java program
Hi,
In our Java application, we want to use the SAP Webservices. I dont know much about authentication mechanism used by SAP. Can any one please help me with any sample code how to Call SAP webservice in Standalone Jave Program. I searched alot on the web regarding this, but helpless. Please help me.
Thanks,
MohanHi Mohan,
You need an account for the ES Workplace. I'm afraid this is not free, e.g. check [SAP NetWeaver, Composition Subscription|https://www.sdn.sap.com/irj/sdn/subscriptions/composition].
But I thought you wanted to play with a WSDL [you already had at hand|Sample code to access BAPI Web services from JAVA required;? -
How to call a VB application from Java
Hi,
does anybody know how to call a VB application from java.
Would appreciate if you can provide me with an example.
thankstry exec()ing the cad program with the name of the file as a command line parameter...
Runtime.getRuntime().exec("CADProg.exe Test.prt");
i have no clue if this will work but it seems like it's worth a try. -
Problem while running dos command from java program
Dear friends,
I need to terminate a running jar file from my java program which is running in the windows os.
For that i have an dos command to find process id of java program and kill by using tskill command.
Command to find process id is,
wmic /output:ProcessList.txt process where "name='java.exe'" get commandline,processid
This command gives the ProcessList.txt file and it contains the processid. I have to read this file to find the processid.
when i execute this command in dos prompt, it gives the processid in the ProcessList.txt file. But when i execute the same command in java program it keeps running mode only.
Code to run this command is,
public class KillProcess {
public static void main(String args[]) {
KillProcess kProcess = new KillProcess();
kProcess.getRunningProcess();
kProcess = new KillProcess();
kProcess.readProcessFile();
public void getRunningProcess() {
String cmd = "wmic /output:ProcessList.txt process where \"name='java.exe'\" get commandline,processid";
try {
Runtime run = Runtime.getRuntime();
Process process = run.exec(cmd);
int i = process.waitFor();
String s = null;
if(i==0) {
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(process.getInputStream()));
while ((s = stdInput.readLine()) != null) {
System.out.println("--> "+s);
} else {
BufferedReader stdError = new BufferedReader(new
InputStreamReader(process.getErrorStream()));
while ((s = stdError.readLine()) != null) {
System.out.println("====> "+ s);
System.out.println("Running process End....");
} catch(Exception e) {
e.printStackTrace();
public String readProcessFile() {
System.out.println("Read Process File...");
File file = null;
FileInputStream fis = null;
BufferedReader br = null;
String pixieLoc = "";
try {
file = new File("ProcessList.txt");
if (file.exists() && file.length() > 0) {
fis = new FileInputStream(file);
br = new BufferedReader(new InputStreamReader(fis, "UTF-16"));
String line;
while((line = br.readLine()) != null) {
System.out.println(line);
} else {
System.out.println("No such file");
} catch (Exception e) {
e.printStackTrace();
return pixieLoc;
} when i remove the process.waitFor(), then while reading the ProcessList.txt file, it says "No such file".
if i give process.waitFor(), then it's in running mode and program is not completed.
Colud anyone please tell me how to handle this situation?
or Is there anyother way to kill the one running process in windows from java program?
Thanks in advance,
SathishHi masijade,
The modified code is,
class StreamGobbler extends Thread
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
this.is = is;
this.type = type;
public void run()
try
InputStreamReader isr = new InputStreamReader(is, "UTF-16");
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
ioe.printStackTrace();
public class GoodWindowsExec
public static void main(String args[])
try
String osName = System.getProperty("os.name" );
String[] cmd = new String[3];
if( osName.equals( "Windows 95" ) )
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
} else {
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]);
Process proc = rt.exec(cmd);
System.out.println("Executing.......");
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
}when i execute the above code, i got output as,
Execing cmd.exe /C wmic process where "name='java.exe'" get commandline,processid
and keeps in running mode only.
If i execute the same command in dos prompt,
CommandLine
ProcessId
java -classpath ./../lib/StartApp.jar;./../lib; com.abc.middle.startapp.StartAPP 2468
If i modify the command as,
cmd.exe /C wmic process where "name='java.exe'" get commandline,processid > 123.txt
and keeps in running mode only.
If i open the file when program in running mode, no contents in that file.
If i terminte the program and if i open the file, then i find the processid in that file.
Can you help me to solve this issue? -
Passing argument to shell script from java program
str="/bin/sh -c /root/PWAppSh/StartSH.sh";
p = rt.getRuntime().exec(str);
above is the code snippet of java program for calling the shellscript
when i pass a argument to the shell script from my java program it wont get accepted in shell script as an input
when i do following changes in above code it wont work :---
str="/bin/sh -c /root/PWAppSh/StartSH.sh para1 para2 para3 ";
p = rt.getRuntime().exec(str);
para1,para2 and para3 wont get as argument for the shell script
how this can be done
thanks
reply "ARGENT"Argent.
Read this:
Navigate yourself around pitfalls related to the Runtime.exec() method -
Calling a Web Service from Java
Our java guru (who is out sick....AHHHH) created all the calls that are needed to access the web service that he has running. For example the call getLongList(String user, String password) will return a list of all outstanding transactions. He made a jar file that has service has class files for PortType, Service, Service Locator and Soap Binding stub.
How do I call this web service from java? Do I have to import it into my classpath? or just call these parameters from within my java code?never mind...i got it
Maybe you are looking for
-
i downloaded an upgrade from itunes last night to os5.1 i think. it said there was a problem with the download. now my phone will not work at all. it just has a picture of the itunes logo ans a picture of a usb cable on it. my computer will not recog
-
How to print "Text" in JAVA(TM)....
Does anyone know how to print "text" using Java? - Here's an example output... NOTE: # == 'empty spaces' --------------------------- <- Paper |###################| |####Welcome#########| |###################| |########to##########| |###########JAVA(T
-
Freight condition type Vs. Tax Condition Types
HI, Can anyone tell me why Freight condition types Post to accruals during MIGO (GR posting) and Tax conditions types don't? Can I provide me a solution to allow Tax condition types to post to accruals during MIGO just like the freight. Thanks. Ricke
-
Quicktime problem, again
i know the quicktime question mark thing has been done to death, but none of the previous posts seem to address the issue i'm having. running leopard, problem occurs on both safari and firefox. have downloaded windows media player 9 and the flip 4 ma
-
Hi All 1 more person with wifi issues with the iphone 5. I bought 2 iphone 5's, 1 black & 1 white. After 1 week I lost the wifi connectivity. I reset the phones....no I reset the modem & changed the modem name...fixed one I have tried just about ever