Running a command from java code
hi all,
There is a command
"java -jar selenium-server.jar -interactive"
which i am running through command prompt after going to D:\MyFolder\Examples .
i want to execute this command using java code .please help
subratjyetki wrote:
please answer in detail or if posible can u give the code for thisOnce more -
The detail is given in the reference. Why don't you read it?
I could give you the code but it will cost you �100 per hour.
Similar Messages
-
Running ls command from Java stroed procedure no output
Hi ,
I am trying to run ls command from java stored procedure in oracle
Process p = Runtime.getRuntime().exec("ls");
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("output of the command run:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
from java stored procedure in oracle.
i get output of println statments but it does not go into while loop to print from stdInput.
Result of running Java stored procedure is -
output of the command run:
Call completed.
when i run the program on client side it works fine.
Has anybody tried this from java stroed procedure.
Thanks,
JagJag,
Actually, the question of whether it works for me seems to depend on the version of the OS (or Oracle). On RedHat Linux (Oracle 8.1.6) it didn't work at all, but on Solaris (Oracle 9.0.2) it did. Here's the output from that run:
SQL> /
output of the command run:
init.ora
initDBPart9i.DBPSun01.ora
initdw.ora
lkDBPART9I
orapw
orapwDBPart9i
spfileDBPart9i.ora
Done
PL/SQL procedure successfully completed.
But, I did need to change a line of your code to this:
Process p = Runtime.getRuntime().exec("/usr/bin/ls");
your original was:
Process p = Runtime.getRuntime().exec("ls");
You might consider, if possible, use of some of the Java File classes instead of ls, as this might make things more predictable for you. There were some examples in oramag.com a few months ago, but they were pretty simple (you might not need them).
Hope this helps,
-Dan
http://www.compuware.com/products/devpartner/db/oracle_debug.htm
Debug PL/SQL and Java in the Oracle Database -
Running sqlplus scripts from Java code?
hi
I need to programmatically run sqlplus scripts from Java code on a machine that doesn't have sqlplus installed.
Is there any Java class library available for doing this?The Ant approach could probably work for me, thanks for the tip.
The setup seems rather complex however, given the simplicity of the task. I would prefer just running a Java based SQL*Plus from in a separate process or doing this via an API that would allow me to run SQL*Plus scripts (parse script, substitute variables, run statements).
Oracle SQL Developer v1.1 appears to include an API that does exactly this.
The ScriptParser, Substitution and SQLPLUS classes in the oracle.dbtools.raptor.scriptrunner package (oracle.sqldeveloper.jar) seem to do just what I need based on my tests.
Can I use these classes for this purpose in my application? Is repackaging allowed?
Does Oracle have any plans for releasing this sort of functionality separately e.g. as part of the Instant Client? -
Running ssh command from java and then answering password prompt
Hi,
I have a situation that has not solved yet. I am running ssh command from unix terminal without any problem, and then i enter password.
For example :
[oracle@fuata]:/export/home/oracle> ssh -N [email protected] -L 9901:127.0.0.1:9999
Password:
It is working. I have question that how can i perform this in java? I am thinking that i can run ssh command by using Runtime Class, it is ok. But how can i answer the password? I am a bit confused. Is there any example looks like this?
Thanks for responses.futi wrote:
Thanx. Firstly i insisted to do this without jsch but actually this is harder than jsch. I edit some of code pieces PortForwardingL.java and could run it. It works problem-free. Could you say why you "insisted" on this approach. It can't be for speed+ since jsch is very fast. It can't be for portability+ since jsch is portable but the use of Runtime.exec() requires the installation of ssh software. It can't be because of limitations+ since jsch is a fully featured library. It can't be for security+ since jsch is secure. It can't be for ease of use+ since jsch is much easier to use than ssh with Runtime.exec(). Unless it's a licensing issue, it can't be for commercial+ reasons since jsch is free. The only reason I can think of why one would "insisted" on this approach is if it is for some college project. -
To run a command using java code
hi all,
There is a command
"java -jar selenium-server.jar -interactive"
which i am running through command prompt after going to D:\MyFolder\Examples .
i want to execute this command using java code .please helpsubratjyetki wrote:
please answer in detail or if posible can u give the code for thisThe detail is given in the reference. Why don't you read it?
I could give you the code but it will cost you ?100 per hour. -
How to run system commands from JAVA
Hi Friends,
How to run windows system commands from JAVA
Runtime r=Runtime.getRuntime();
r.exec("dir");
Throwing following Exception
CreateProcess :dir error=2
Thanks in advance
HamsaHi ,
in Windows NT this is not possible, you can use the following :
Runtime r=Runtime.getRuntime();
StringBuffer sbuf = new StringBuffer();
String dir = new String();
java.lang.Process proc = r.exec("cmd /c dir");
InputStream is = proc.getInputStream();
int ch ;
while((ch=is.read() ) != -1)
sbuf.append((char)ch);
is.close();
dir = sbuf.toString();
System.out.println(dir ); -
Executing sqlplus / sqlldr command from java code
hi,
I have my application on one server(tomcat) and oracle server is installed on other server. i.e. Both are on different machine.
Now i want to run sqlplus / sqlldr command on oracle server from my java code.
Again my script for lodder command is in temp of tomcat.
How to do that?
Thanks,Hi,
I am using JDBC to executed queries...but i need to run sqlplus command to run script if some condition is satisfied and same for sqllodder to load large record like 500000. This code is in the thread and is working fine for same machine. Need to execute it on another machine where oracle is installed.
From command prompt i am able to run sqlplus on Oracle server. Same command I am not able to run from the code. I have shared bin direcotry of Oracle from server.
Let me know if any query
Regards,
Edited by: Sun_Nut on Dec 16, 2007 9:53 PM -
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? -
I want to run this program from my java code,
In Linux(ubuntu) I write this command to open the program window
$ paraFoam -case /home/saud/OpenFOAM/OpenFOAM-1.5/run/tutorials/icoFoam/cavity/In my java code I wrote it like this("/home/saud/OpenFOAM/OpenFOAM-1.5/bin/" is the path of the program):
String command = "/home/saud/OpenFOAM/OpenFOAM-1.5/bin/paraFoam " +
"-case /home/saud/OpenFOAM/OpenFOAM-1.5/run/tutorials/icoFoam/cavity/";
final Process myProcess = Runtime.getRuntime().exec(command);
BufferedReader buf = new BufferedReader(new InputStreamReader(
myProcess.getInputStream()));
String line;
while ((line = buf.readLine()) != null) {
System.out.print(String.format("%s\t\n", line));
buf.close();
int returnCode = myProcess.waitFor();
System.out.println("Return code = " + returnCode); Return code = 0
but the program is not opening
Edited by: Saud.R on Apr 11, 2009 3:37 AMWelcome to the Sun forums.
I am not sure of the answer to your question, but people who use Processes regularly, warn other users to ensure they are also doing something with the error stream of the process, otherwise it can hang as you describe. -
How to execute solaris lpd printing command from java code
hi folk,
I want to print a post script file on a network printer (my java code will receive the Printer's IP Address and the filename ) , i'm using the solaris lpd printing command :
lpadmin -p banana_ps -o protocol=bsd,dest=IP -v /dev/null
-m netstandard -T PS -I postscript
my question is how execute this command from the java code :)
i really appreciate ur advicesHi,
See RunTime.getRuntime ().exec (...).
Hope that help,
Jack -
Running .jar files from Java code
Hi.
I am designing a sort of platform to run some games which are saved in .jar files. Basically this platform is a menu from which the user can select the game which he/she wants to run. It also has the feature of adding new games.
Is is possible to run the .jar file from within java code?
Thanks for any help!
Krt_maltaJust list the jar in the classpath list and call the class in the jar.
-
Running .bat files from java code
Dear Forum,
I have seen numerous postings on the web about this question, still I have found no answer that works (for me)
I�m trying to run a simple .bat file from a piece of java code , however it does not work. No error message , but still.
Does anyone have a tip?
best regards
temuj
try{
String cmd = "cmd.exe C:\\mybat.bat";
Runtime.getRuntime().exec(cmd);
catch(IOException e){System.out.println("ERROR: "+e);}Message was edited by:
temujin"cmd.exe C:\mybat.bat" is being passed to the OS for execution
what happens when in a terminal/dos window you execute letter for letter:
cmd.exe C:\mybat.bat
The output will be identical to what is happening when java makes this call. -
Running windows command through java code
Hello
i want to execute jar.exe through java code , i have written following piece of code , but it isn't working
ProcessBuilder processBuilder = new ProcessBuilder(new String[]{"cmd.exe","/c","%java_home%\\bin\\jar.exe"});
Process process = processBuilder.start();
BufferedReader inputReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line = inputReader.readLine();
while(line != null){
System.out.println(line);
line = inputReader.readLine();
does anybody knows why
Regards
Edited by: Mayur Mitkari on Mar 5, 2013 10:19 PM
Edited by: Mayur Mitkari on Mar 5, 2013 10:20 PM
Edited by: Mayur Mitkari on Mar 5, 2013 10:20 PMsorry for that , but the
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec(new String[]{"cmd.exe","/c","jar"});
proc.waitFor();
int i = proc.exitValue();
this code was different from first one
and in case of Process if runtime .exec is succesful it is wainting for long time , in this case i want if the runtime.exec is succesful something should be returned
Regards -
Hi ,
I would appreciate if anyone could tell me how to run DOS command such as "del" using JAVA language .Thank you.<steps onto soapbox>
Surely for something like 'del' we should be advocating a non-OS specific method so we don't lose sight of Java's cross platform abilities.
If it has to run an OS specific thing fine, but please look for a non OS specific solution first.
<steps off soapbox> -
How to run solaris commands through java code ....
Hi,
actually i want to run some solaris commands for zipping some files on Solaris OS...
any idea how can i do that ?
thankspublic class TABLES
public static void main( String[] args )
//database is connected
try
Connection con = null;
Statement stmt = null;
String strShowTables = "";
ResultSet resultSet = null;
// CBA Statistics period is m_lStatisticsPeriod minutes
con = DriverManager.getConnection( g_strRWURI, g_strRWUsername, g_strRWPassword );
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("use db");
resultSet = stmt.executeQuery(strShowTables);
String tableName = "";
while(resultSet.next()){
tableName = resultSet.getString(1);
System.out.println(tableName);
break;
String strCmd = "tar cvzf file.tar.gz var/lib/mysql/db/GROUPS.*";
Process p= Runtime.getRuntime().exec(strCmd);
System.out.println(strCmd);
stmt.close();
rs.close();
resultSet.close();
con.close();
catch ( Exception e )
System.out.println( ": Failed to create database connection (" + e.getMessage() + ")" );
e.printStackTrace();
catch ( Throwable t )
System.out.println( " Throwable: " + t.getMessage() );
t.printStackTrace();
}//end of main mehtod
}//END OF CLASSi hava tried the above code... what the problem is
when is run that command on shell > tar cvzf file.tar.gz var/lib/mysql/db/GROUPS.*i works fine but in code even though it didn't give any error but the created "file.tar.gz" is empty...
Edited by: aftab_ali on Apr 7, 2009 7:15 AM
Edited by: aftab_ali on Apr 7, 2009 7:17 AM
Maybe you are looking for
-
How to check data in a cluster table?
Hello I am new to BW and SDN. I have to see data in a cluster table. I went to SE11, selected data type as KOMV, it displayed table, but data content button is greyed out. Can someone please tell me how to view the data? Thanks Priya
-
How do I install camera raw updates to the mac app store version of elements 10
In the mac app store version of Elements 10 there is 'get updates' link on the help menu. And when I try to do it manually from a download I get a message telling me that 'this update no applicable'.
-
How to display database name in page footer in webi report
Hi Every one, I have migrated deski report from BO 6.5 to BI 4.1. and converted Deski to WEBI in 4.1. In Bo 6.5 page footer displaying database name but BI 4.1 it showing database type (like Oracle 10g,9i ..etc..). I want database name in page footer
-
Unbelievable! After 1 day of usage (about 3 hours) , I found the external edges of body completely discolored. Looking the locations, it sounds like the wearing off has been due to the palms of my hands but I have never experienced something like tha
-
Trouble setting up X with FreeBSD 7.1 on my Thinkpad T60 1951-FCG
Hi! I'm having some trouble setting up X on my Thinkpad T60 1951-FCG running FreeBSD 7.1. When I run whatever config, either the one I get from X -configure or one edited after my settings, all I get is a black screen. The screen is a tad bit lighte