Executing procedure at regular interval from java program
hi,
I want to write java program that will execute procedure at regular interval,
please give me hint how it will happen??????
Use THREAD and Thread.sleep
Similar Messages
-
Error while trying to execute a unix shell script from java program
Hi
I have written a program to execute a unix shell script in a remote machine. I am using J2ssh libraries to estabilish the session connection with the remote box.The program is successfully able to connect and authenticate with the box.
The runtime .exec() is been implemented to execute the shell script.I have given below the code snippet.
try {
File file_location = new File("/usr/bin/");
String file_location1 = "/opt/app/Hyperion/scripts/daily";
String a_mib_name = "test.sh";
String cmd[] = new String[] {"/usr/bin/bash", file_location1, a_mib_name};
Runtime rtime = Runtime.getRuntime();
Process p = rtime.exec(cmd, null, file_location);
System.out.println( "Connected to the server1" );
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = br.readLine();
while(line !=null)
System.out.println(line);
line = br.readLine();
br.close();
p.getErrorStream ().close ();
p.getOutputStream().close();
int retVal = p.waitFor();
System.out.println("wait " + retVal);
//session.executeCommand("ls");
catch (IOException ex) {
I get an error message
Connected to the server
java.io.IOException: Cannot run program "/usr/bin/bash" (in directory "\usr\bin"
): CreateProcess error=3, The system cannot find the path specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at SftpConnect.main(SftpConnect.java:143)
Caused by: java.io.IOException: CreateProcess error=3, The system cannot find th
e path specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
I am sure of the file path where the bash.sh and test.sh are located.
Am i missing something? Any help would be greatly appreciated.
Thanks
SenthilHi, I am using a simple program to connect to a RMI server and execute shell script. I use the Runtime.exec aommand to do the same.
The script is sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul
The script when run from the server, gives no errors. But when ran using rthe above method in java, gives errors as follows,
Mycode:
String command = "/bin/sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
int exitVal = proc.exitValue();
System.out.println("Process exitValue: " + exitVal);
java.io.IOException: CreateProcess: /bin/sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul error=3
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at DecryptTest.main(DecryptTest.java:18)
Can anyone please help -
Is it possible to execute SAPGUI scripts from java program?
Hi everyone..
I need to develop an java applications that executes the SAPGUI script or any technique that execute set of transaction as client.
Is it possible to execute SAPGUI scripts from java program? if so, how it can be achieved? is there any other technique to achieve above mention scenario?.
it will be more helpful, if docs related to that are shared..
Thanks in advanceOh, bummer. Would be much more convenient if I could just use iTunes for everything. Can't stand WMP. I wonder if WinAmp might be a good compromise?
Thanks for this answer . . .
Sharon -
Execute ConcurrentRequest from java program
In order to execute concurrent request from java program are this 3 lines enough :
1)ConcurrentRequest concurrentrequest = new ConcurrentRequest(oadbtransaction.getJdbcConnection());
2)int i = concurrentrequest.submitRequest("some value", " some value", "some value", null, false, vector);
3)oadbtransaction.commit();
*******************************8
I am asking because while executing ConcRequest from PL/SQL I have to call a functin : fnd_global.apps_initialize(user_id ,resp_id, app_id) prior to executing FND_REQUEST.SUBMIT_REQUEST.
Is there any equivalent in java for apps_initialize?
thanks in advance.hi
u can call the FND_global using callable statement
DBTransaction txn = getDBTransaction();
CallableStatement cs =
txn.createCallableStatement("begin fnd_global.apps_initialize(:1, :2,:3);end;");
try
cs.setString(1, getOADBTransaction().getUserId() );
cs.setString(2, getOADBTransaction().responsibilityId());
cs.setString(3, getOADBTransaction().getApplicationID());
cs.execute();
cs.close();
catch (SQLException sqle)
try { cs.close } catch (Exception(e) {}
throw OAException.wrapperException(sqle);
thanx
Pratap -
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? -
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 approve the step from java program ?
Hi all,
I want to approve a step from java program.
I call the store function "wf_notification.setattrtext" & "wf_notification.respond".
It's not work.
The notification's status become to 'CLOSE', but PO_REQUISITION_HEADERS_ALL.AUTHORIZATION_STATUS is 'IN PROCESS'.
And I try to approve the flow from oracle web gui and it's OK !
The notification's status become to 'CLOSE', but PO_REQUISITION_HEADERS_ALL.AUTHORIZATION_STATUS is 'APPROVED'.
The java program as follows, and '1099999' is notification id.
Can anyone please please please help me?
Thanks, all.
Gavin
===================================================================================================
import java.util.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.rmi.*;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public class CommitPR
public static void main(String[] aArgs) throws Exception
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@10.1.1.1:1521:ORA";
String user = "user";
String password = "password";
Class.forName(driver).newInstance();
String sql;
Connection conn = null;
Statement callStmt;
conn = DriverManager.getConnection(url, user, password);
conn.setAutoCommit(true);
callStmt = conn.createStatement();
sql = "{ CALL WF_NOTIFICATION.SETATTRTEXT ('1099999','RESULT','APPROVE') }";
System.out.println("sql=" + sql);
callStmt.execute(sql);
sql = "{ CALL WF_NOTIFICATION.RESPOND ('1099999','ARRPOVED','EIP_ADMIN') }";
System.out.println("sql=" + sql);
callStmt.execute(sql);
callStmt.close();
conn.close();
===================================================================================================Hi,
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 edit the existing data in the XML file from java programming.
Hi all
i am able to create XML file with the sample data as below from java programming.
i need sample code on how to edit the existing data in the XML file?
for example
<?xml version="1.0"?>
<mydata>
<data1>
<key1>467</key1>
<name1>Paul</name1>
<id1>123</id1>
</data1>
<data2>
<key2>467</key2>
<name2>Paul</name2>
<id2>123</id2>
</data2>
</mydata>
i am able to insert the data in the XML.
now i need sample code on how to modify the data in the above XML file from the java programming for only key2,name2,id2 tags only. the remaining tags data in the XML file i want to keep same data except for key2,name2,id2 which are i want to modify from java code
Regards
Sunil
[points will be always rewardable]hi
u need a parser or validate the xml file for to read the xml file from java coding u need for this
xml4j.jar u can download this file from here
http://www.alphaworks.ibm.com/tech/xml4j
or we can use the SAX(simple API for XML)
some sample applications for this
http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
http://www.developertutorials.com/tutorials/java/read-xml-file-in-java-050611/page1.html
http://www.xml-training-guide.com/e-xml44.html
let me know u need any other info
bvr -
How to access database file on CDROM from Java Programe??
Hello friends,
I am making online exam application.
I want my question database to be reside on CDROM.
but i am not getting any idea how to make DSN or static path that resolute the path that i have mentioned for CDROM.
basically i want to know how to access CDROM from Java Programe????
Thanks in advance
Navik PathakOnce you mounted the CDROM (something maybe as /media/cdrom) as a file system (or assigned a drive letter to it like D: or F: or whatever), the files are accessible normally.
-
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. -
How to connect iseries green screen from java program
how to connect iseries green screen from java program to get the data in the DB files ,here the DB is DB2/400
Just some Friday fun. Use the telnet program that comes with Windows and supports VT escape sequences.
import java.io.*;
import java.net.*;
public class AutoTelnet {
private static Socket s;
public static void main(String[] args) throws Exception {
Thread t = new Thread() {
@Override public void run() {
try {
s = new ServerSocket(5555).accept();
} catch (IOException ex) {
ex.printStackTrace();
t.start();
Process p = new ProcessBuilder("cmd", "/C", "start", "telnet", "127.0.0.1", "5555").redirectErrorStream(true).start();
t.join();
PrintStream ps = new PrintStream(s.getOutputStream());
ps.println("Screen will be cleared in 5 seconds");
ps.println("5");
Thread.sleep(1000);
ps.println("4");
Thread.sleep(1000);
ps.println("3");
Thread.sleep(1000);
ps.println("2");
Thread.sleep(1000);
ps.println("1");
Thread.sleep(1000);
ps.println("\u001b[2J");
Thread.sleep(5000);
} -
How to create a file under web application root from java program
how to create a file under web application root from java program like an action class?
like an action class?Huh? What exactly is your requirement?
Creating a file is usually done with java.io API. Read the java.io tutorials how to play with files. -
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"); -
SOLVED: How To Use LDAP over SSL (no certs) from java program
Trying to connect to OID from Java program (using Grocery Store demo as a test). Want to use SSL with no server certificate. OID is configured, and ldapsearch -U 1 works.
Tried using URL with ldaps, or adding SECURITY_PROTOCOL,"ssl". In both case the error is 'simple bind failed'.
Samples on OTN say this should be possible, but then only have code for the non-ssl connection.
Posting from others with this same question don't seem to have been answered.
Message was edited by:
user590350
I have found that using ConnectionUtil.getSSLDirCtx() from Oracle will make a no-authentication SSL connection. An example in the sample code would be useful.Even with Java APIs, There is a way to talk through SSL without bothering about certificates. It's just that you will have to write some code and make some changes in settings.
Read following to get further information on the same.
http://kiranthakkar.blogspot.com/2007/04/dummny-certificate-authentication.html
I don't know or I won't comment whether it's the right approach or not but it's definitely a work around.
Thanking You
Kiran Thakkar -
Execute a Linux konsole command from Java
Hy,I am having problems when trying to execute a command for konsole from java.
This is a part of my code
try {
Runtime.getRuntime().exec("konsole");
catch (IOException ex) {ex.printStackTrace();}this code opens the Linux konsole ; is the a method to append a command for Linux from java??
ThanksOK
this is what I am trying to do : by pressing a button
in a JFrame I want to start Snort (the exact command
is snort -c /etc/snort/snort.conf )
What I want is the following: I press that button
and the Konsole in Linux opens and that command to
be executed I would just use the Process.getInputStream() method to retrieve what Snort said and display that in a JTextArea or something... why bother launching it in a terminal?
I don't know if Snort is a daemon or what... if it's a daemon, you're not going to get much output from it... it'll fork itself into the background and exit.
If it isn't a daemon, then you can either just redirect the output to a file, a la:
konsole snort /etc/snort/snort.conf > /tmp/snort.outand do a "tail" sort of monitoring on the file. You could also just keep that process up in a different thread, and use a timer to periodically update the output into a JTextArea (this would also allow you to be notified when the process ended). Finally, you could wrap your command in a script and execute it that way.
Maybe you are looking for
-
Dear Apple, I use the same Apple ID on my iPad mini and my iPhone 5. My iPhone 5 was stolen on may 12, 2013. Do you know how to get it back?
-
InDesign CS3 vs. Framemaker/Ventura
Has anyone used InDesign CS3 for producing long, text-intensive, books? How does it compare to Framemaker or Ventura? Will InDesign handle multi-page tables, for example? Is it possible to rotate multi-page tables 90 degrees (landscape table on a por
-
Saving to normal.dot in Word for Mac
Hi! I don't know if this question belongs here but I couldn't seem to find any other forum for it. So... how do I save to normal.dot in Word for Mac? I can't find the normal.dot template. Hope someone can hekp - thanks
-
How to sort data (i.e. sort by last name) in a related ?
Hello, Is there a way to sort automatically records by "last name" in my related "contact" of my account view ? Even manually, we do not have any arrow ! Many thanks and have a nice day.
-
I need detail information about inventory revaluation, like Tutorial process , import data from DWT , and also how we can do it, and also solution for following matter :Now we have some problem in balance of inventory account, some of them has negati