Launch 2 batchs from a java program
Hi,
My pb is the following one:
I launch a batch file from my java program. This batch launch another program. But it seems that the java program take back the hand and stop the execution of the last program.
How can I make the java program waiting?
Thanks in advance
Thanks Felipe.
I've tried your suggestion and I've discerned the real bug. In fact, it's the program that I launch through the batch file which don't perform.
Here is my batch file:
C:\program files\pvcs\vm\win32\bin\pcli.exe run -sC:\program files\pvcs\vm\win32\bin\noexiste.pcli %1 %2 %3
In fact, it has to launch pcli.exe, which has to launch a script.
The pb is that when I run the batch file manually, it works. So, it comes from the java prg. Here is the command lines in my program java:
try
String cmd = "C:/Progra~1/Pvcs/Vm/Win32/Bin/transfert.bat";
String[] cmdArray = { cmd, Str_LabelModule, Str_FichierSauvegarde, Str_AccesArchive };
Prc_MyProcess = Rt_MyRuntime.exec(cmd);
System.setProperty("ATTENTE", "VRAI");
while(!b_stop)
if(!System.getProperty("ATTENTE").equals("VRAI"))
b_stop = true;
else
Thread.sleep(1000);
}catch (Exception exc) {exc.printStackTrace();}
I tried this program with a simple batch (echo %1 %2 %3 > c\toto.txt) and it works.
Have you an explanation for this?
Similar Messages
-
Launching JNLP from a Java Program
Hi All,
Can anyone please let me know if I can launch a JNLP from a java program. The requirement is that there are two applications and I need to integrate both of them. So I need to call the other program from this. Can this be accomplished.
Thank you,
Thanks and Regards
Mouli[Desktop.browse(jnlpUri)|http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html#browse(java.net.URI)]
-
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 can I execute a batch file from my java program
Hi,
Can someone help me or direct me to a link,
How can I execute a DOS batch file from my java program?
ThanksYou will need to grab a handle to the process's
outputstream so u can see its output.The OP didn't mention any output from any batch file;
nor any input for that
matter,so lets not complicate matters here for now
ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
I'm sure it wasn't intentional that your post appeared to be bristling with attitude. -
Sending POSIX signal to an external subprocess from a java program
I'm programing in forte for java under linux-mandrake, I've execute an external subprocess with the runtime and Process clases, I need to send the 2� POSIX signal to this external subprocess, I mean de SIGINT signal, I know that you can send a signal from a shell just doing:
Kill -2 pid // the SIGINT signal is the 2 POSIX signal
I know that there is another system-call like : kill(int signal, int pid) that any one can send from a c program.
Althought I don't know how can I get the pid of a suprocess, because I Know that there is the systemcall in c like:
int getpid() wich gives the pid of the current process, but I need to have the pid of a subprocess not the current one.
The thing is that I do not know how can I do it from a java program, I mean that to send a signal to a subprocess it will work using system-calls, but I do not know if I can insert system call in a java program, I've been thinking about doing it using a linux script like:
#!bin/bash
$a = pidof /home/maude-linux/bin/maude.linux
# this is the path of the process wich is running
kill -2 a$
and the run this script from a java program doing an exec(sh script.bin)
but by the moment I must be doing something wrong in the script because I find mistake in it, it gives me mistake in the assign sentence , I mean:
$a = pidof /home/maude-linux/bin/maude.linux
# this is the path of the process wich is running
I'm not used to program shell scripts, perhaps I'm doing something wrong, is there something wrong in this sentence?.
I would aprecciate some help about this, or if somebody have some idea how to do it in java, I repeat I need to send a signal to a external subprocess wich is launched from a java program by the process and runtime clases, and I need to send a SIGINT signal to the subprocess, I hope that some body can give some suggestion or some code explaining the situationAre the portions of bash-code verbatim in your post?
When yes, they look suspicious!
Instead of
#!bin/bash
#!/bin/bash
would be better.
$a = pidof /home/maude-linux/bin/maude.linux
does not look good either.
If you have command "pidof" telling the pid based on the path name of the executable passed to it as its argument, you can have the output of this program in a shell script like this:
a=$( pidof /home/maude-linux/bin/maude.linux )
Then through $a you will refer to the value of the variable "a":
kill -SIGINT $a
A pidof script could look like this (apart from error handling):
ps -ef|awk '{if (NF>=8 && $8=="'"$1"'") print $2;}'
This works for me; your mileage may vary. -
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 ) {
} -
Executing a stored procedure from a java program
Hi.. how can i call a oracle stored procedure from a java
program. the OSP has four IN parameters and one OUT parameter(a
cursor). when i try this way.. i get an error
con = DriverManager.getConnection(url, "stored", "stored");
CallableStatement cs =
con.prepareCall(
"{call stored_proce_1(?,?,?,?,?)}");
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.setString(2, "14541");
cs.setString(3, "gen");
cs.setInt(4, 0);
cs.setInt(5, 5);
ResultSet rs =cs.getResultSet();
while(rs.next()){
System.out.println(rs);
appreciate ur help.
qsI'm no expert on this, but I have a similar call where I fetch
an Oracle REF CURSOR from a call to a stored function. If you
fetch the cursor as an Object from your CallableStatement, you
can then cast it to a ResultSet e.g.
mystatement.executeUpdate();
ResultSet rs = (ResultSet) mystatement.getObject(1);
Then you should be able to loop through your ResultSet as usual.
Good luck!
Chris -
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);
} -
How to start java.exe from a java program in windows ?
Hi,
I did like to know, if its possible to run java.exe from a java program on windows ? The java.exe should be visible from checking the processes that are currently running using the Task Manager on windows.Runtime.getRuntime().exec("java Sample");
-
How to have an Oracle procedure send and receive value from a java program.
The below procedure is place inside a package. This procedure "get_extract_ready_headers " is selecting columns store_number, terminal_number, tran_number, tran_date, cust_id from the source REX_HEAD_EXTRACT table. This information is selected into a ref cursor. The data has cust_id field which is encrypted. How do I modify the procedure get_extract_ready_headers and accomplish 2 things?
1. Make this procedure to read the "cust_id" value from the source table and send the value to a Java program "getheaderinfo" (this java program decrypts the cust_id field).
2. When we get the unencrypted value back from the Java program, make the procedure accept this decrypted value and use it to update CUST_ID value in the target table TRAN_HEAD table. I am using Oracle 11.2.0.2, and TOAD 10.5.1.3.
-- Procedural code
PROCEDURE get_extract_ready_headers (p_records OUT SYS_REFCURSOR)
IS
BEGIN
OPEN p_records FOR
SELECT store_number, terminal_number, tran_number, tran_date, cust_id FROM REX_HEAD_EXTRACT;
END;--Table Structure for source table REX_HEAD_EXTRACT
CREATE TABLE REX_HEAD_EXTRACT
REX_SEQ_NBR NUMBER(20),
REVISION_NUMBER NUMBER,
DAY NUMBER(3),
RESA_TRAN_SEQ_NO NUMBER(20),
BUSINESS_DATE DATE,
TRAN_SEQ_NBR NUMBER(12),
ORG_NUMBER NUMBER,
STORE_NUMBER NUMBER,
TRAN_DATE DATE,
TERMINAL_NUMBER NUMBER,
TRAN_NUMBER NUMBER,
TRAN_TIME DATE,
BATCH_NUMBER VARCHAR2(8 BYTE),
BATCH_TYPE VARCHAR2(4 BYTE),
TRAN_TYPE VARCHAR2(4 BYTE),
SUB_TRAN_TYPE VARCHAR2(4 BYTE),
CLERK_CODE VARCHAR2(15 BYTE),
TRAN_TAXABLE_AMOUNT NUMBER(12,2),
TRAN_TAX_TOTAL NUMBER(12,2),
TRAN_GROSS_TOTAL NUMBER(12,2),
COUP_TOTAL NUMBER(9,2),
MKD_TOTAL NUMBER(9,2),
EMPLOYEE_NUMBER VARCHAR2(15 BYTE),
EMPLOYEE_NAME VARCHAR2(40 BYTE),
TRAN_ALTTAXABLE_AMOUNT NUMBER(12,2),
TRAN_ALTTAX_TOTAL NUMBER(12,2),
SALE_AMOUNT NUMBER(9,2),
RETURN_AMOUNT NUMBER(9,2),
RETURNED_AMOUNT NUMBER(9,2),
NETCASH NUMBER(12,2),
TENDER_CODE VARCHAR2(4 BYTE),
MULT_RCPT VARCHAR2(1 BYTE),
SPLIT_TENDER VARCHAR2(1 BYTE),
RTN_WITH_PURCHASE VARCHAR2(1 BYTE),
RTN_WITH_RCPT VARCHAR2(1 BYTE),
REASON_CODE VARCHAR2(4 BYTE),
PASSWORD VARCHAR2(10 BYTE),
RINGTIME DATE,
CUST_NUMBER VARCHAR2(12 BYTE),
CUST_ID VARCHAR2(50 BYTE),
ZIP_CODE NUMBER,
POSTAL_CODE VARCHAR2(9 BYTE),
PV_TIME_LAPSE NUMBER,
ORIG_STORE_NBR NUMBER,
ORIG_TRAN_DATE DATE,
ORIG_TRAN_TYPE VARCHAR2(4 BYTE),
ORIG_TERM_NBR NUMBER,
ORIG_TRAN_NBR NUMBER,
ORIG_SALE_AMT NUMBER(12,2),
ORIG_TENDER_CODE VARCHAR2(4 BYTE),
ORIG_CLERK_CODE VARCHAR2(15 BYTE),
PREV_TRAN_TYPE VARCHAR2(4 BYTE),
PREV_SUB_TRAN_TYPE VARCHAR2(4 BYTE),
GIFT_REGISTRY_ID VARCHAR2(25 BYTE),
NO_OF_ITEMS NUMBER,
TAX_EXEMPT_ID VARCHAR2(18 BYTE),
TRAN_RINGTIME NUMBER,
AUDITED VARCHAR2(1 BYTE),
BATCH_VERSION NUMBER(9,2),
BATCH_SOURCE VARCHAR2(5 BYTE),
CREATE_DATE DATE,
CREATE_ID VARCHAR2(32 BYTE),
CREATE_PROC VARCHAR2(32 BYTE),
MOD_DATE DATE,
MOD_ID VARCHAR2(32 BYTE),
MOD_PROC VARCHAR2(32 BYTE),
TERMINAL_GROUP NUMBER,
USER_DEF_1 NUMBER,
USER_DEF_2 NUMBER,
USER_DEF_3 NUMBER,
USER_DEF_4 NUMBER(12,2),
USER_DEF_5 NUMBER(12,2),
USER_DEF_6 NUMBER(12,2),
USER_DEF_7 VARCHAR2(50 BYTE),
USER_DEF_8 VARCHAR2(50 BYTE),
USER_DEF_9 VARCHAR2(50 BYTE),
MANAGER_NUMBER VARCHAR2(15 BYTE),
MANAGER_REASON_CODE VARCHAR2(10 BYTE),
MANAGER_SWIPED VARCHAR2(1 BYTE),
PHONE_NO NUMBER(11),
KCPOS_KTH_USER_101 NUMBER,
KCPOS_KTH_USER_102 NUMBER,
KCPOS_KTH_USER_103 NUMBER,
KCPOS_KTH_USER_104 NUMBER,
KCPOS_KTH_USER_105 NUMBER,
KCPOS_KTH_USER_106 NUMBER,
KCPOS_KTH_USER_107 NUMBER,
KCPOS_KTH_USER_108 NUMBER,
KCPOS_KTH_USER_109 NUMBER,
KCPOS_KTH_USER_110 NUMBER,
KCPOS_KTH_USER_201 NUMBER(12,2),
KCPOS_KTH_USER_202 NUMBER(12,2),
KCPOS_KTH_USER_203 NUMBER(12,2),
KCPOS_KTH_USER_204 NUMBER(12,2),
KCPOS_KTH_USER_205 NUMBER(12,2),
KCPOS_KTH_USER_206 NUMBER(12,2),
KCPOS_KTH_USER_207 NUMBER(12,2),
KCPOS_KTH_USER_208 NUMBER(12,2),
KCPOS_KTH_USER_209 NUMBER(12,2),
KCPOS_KTH_USER_210 NUMBER(12,2),
KCPOS_KTH_USER_301 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_302 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_303 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_304 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_305 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_306 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_307 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_308 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_309 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_310 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_401 DATE,
KCPOS_KTH_USER_402 DATE,
KCPOS_KTH_USER_403 DATE,
DISC_TOTAL NUMBER(9,2)
CREATE INDEX REX_HEAD_EXTRACT_NDX ON REX_HEAD_EXTRACT
(REX_SEQ_NBR, REVISION_NUMBER, STORE_NUMBER, TRAN_DATE, TERMINAL_NUMBER, TRAN_NUMBER)-- Create table DDL for target table TRAN_HEAD
CREATE TABLE NAVISTOR.KCPOS_TRAN_HEADER_BASE
TRAN_SEQ_NBR NUMBER(12),
ORG_NUMBER NUMBER,
STORE_NUMBER NUMBER,
TRAN_DATE DATE,
TERMINAL_NUMBER NUMBER,
TRAN_NUMBER NUMBER,
TRAN_TIME DATE,
BATCH_NUMBER VARCHAR2(8 BYTE),
BATCH_TYPE VARCHAR2(4 BYTE),
TRAN_TYPE VARCHAR2(4 BYTE),
SUB_TRAN_TYPE VARCHAR2(4 BYTE),
CLERK_CODE VARCHAR2(15 BYTE) NOT NULL,
TRAN_TAXABLE_AMOUNT NUMBER(12,2),
TRAN_TAX_TOTAL NUMBER(12,2),
TRAN_GROSS_TOTAL NUMBER(12,2),
COUP_TOTAL NUMBER(9,2),
MKD_TOTAL NUMBER(9,2),
EMPLOYEE_NUMBER VARCHAR2(15 BYTE),
EMPLOYEE_NAME VARCHAR2(40 BYTE),
TRAN_ALTTAXABLE_AMOUNT NUMBER(12,2),
TRAN_ALTTAX_TOTAL NUMBER(12,2),
SALE_AMOUNT NUMBER(9,2),
RETURN_AMOUNT NUMBER(9,2),
RETURNED_AMOUNT NUMBER(9,2),
NETCASH NUMBER(12,2),
TENDER_CODE VARCHAR2(4 BYTE),
MULT_RCPT VARCHAR2(1 BYTE),
SPLIT_TENDER VARCHAR2(1 BYTE),
RTN_WITH_PURCHASE VARCHAR2(1 BYTE),
RTN_WITH_RCPT VARCHAR2(1 BYTE),
REASON_CODE VARCHAR2(4 BYTE),
PASSWORD VARCHAR2(10 BYTE),
RINGTIME DATE,
CUST_NUMBER VARCHAR2(12 BYTE),
CUST_ID VARCHAR2(50 BYTE) ENCRYPT USING 'AES256' NO SALT,
ZIP_CODE NUMBER,
POSTAL_CODE VARCHAR2(9 BYTE),
PV_TIME_LAPSE NUMBER,
ORIG_STORE_NBR NUMBER,
ORIG_TRAN_DATE DATE,
ORIG_TRAN_TYPE VARCHAR2(4 BYTE),
ORIG_TERM_NBR NUMBER,
ORIG_TRAN_NBR NUMBER,
ORIG_SALE_AMT NUMBER(12,2),
ORIG_TENDER_CODE VARCHAR2(4 BYTE),
ORIG_CLERK_CODE VARCHAR2(15 BYTE),
PREV_TRAN_TYPE VARCHAR2(4 BYTE),
PREV_SUB_TRAN_TYPE VARCHAR2(4 BYTE),
GIFT_REGISTRY_ID VARCHAR2(25 BYTE),
NO_OF_ITEMS NUMBER,
TAX_EXEMPT_ID VARCHAR2(18 BYTE),
TRAN_RINGTIME NUMBER,
AUDITED VARCHAR2(1 BYTE),
BATCH_VERSION NUMBER(9,2),
BATCH_SOURCE VARCHAR2(5 BYTE),
CREATE_DATE DATE,
CREATE_ID VARCHAR2(32 BYTE),
CREATE_PROC VARCHAR2(32 BYTE),
MOD_DATE DATE,
MOD_ID VARCHAR2(32 BYTE),
MOD_PROC VARCHAR2(32 BYTE),
TERMINAL_GROUP NUMBER,
USER_DEF_1 NUMBER,
USER_DEF_2 NUMBER,
USER_DEF_3 NUMBER,
USER_DEF_4 NUMBER(12,2),
USER_DEF_5 NUMBER(12,2),
USER_DEF_6 NUMBER(12,2),
USER_DEF_7 VARCHAR2(50 BYTE),
USER_DEF_8 VARCHAR2(50 BYTE),
USER_DEF_9 VARCHAR2(50 BYTE),
MANAGER_NUMBER VARCHAR2(15 BYTE),
MANAGER_REASON_CODE VARCHAR2(10 BYTE),
MANAGER_SWIPED VARCHAR2(1 BYTE),
PHONE_NO NUMBER(11),
KCPOS_KTH_USER_101 NUMBER,
KCPOS_KTH_USER_102 NUMBER,
KCPOS_KTH_USER_103 NUMBER,
KCPOS_KTH_USER_104 NUMBER,
KCPOS_KTH_USER_105 NUMBER,
KCPOS_KTH_USER_106 NUMBER,
KCPOS_KTH_USER_107 NUMBER,
KCPOS_KTH_USER_108 NUMBER,
KCPOS_KTH_USER_109 NUMBER,
KCPOS_KTH_USER_110 NUMBER,
KCPOS_KTH_USER_201 NUMBER(12,2),
KCPOS_KTH_USER_202 NUMBER(12,2),
KCPOS_KTH_USER_203 NUMBER(12,2),
KCPOS_KTH_USER_204 NUMBER(12,2),
KCPOS_KTH_USER_205 NUMBER(12,2),
KCPOS_KTH_USER_206 NUMBER(12,2),
KCPOS_KTH_USER_207 NUMBER(12,2),
KCPOS_KTH_USER_208 NUMBER(12,2),
KCPOS_KTH_USER_209 NUMBER(12,2),
KCPOS_KTH_USER_210 NUMBER(12,2),
KCPOS_KTH_USER_301 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_302 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_303 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_304 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_305 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_306 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_307 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_308 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_309 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_310 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_401 DATE,
KCPOS_KTH_USER_402 DATE,
KCPOS_KTH_USER_403 DATE,
DISC_TOTAL NUMBER(9,2),
RTA_RTN_AUTCOD VARCHAR2(4 BYTE),
RTA_RTN_COMMID NUMBER,
RTA_RTN_EVNTID NUMBER,
RTA_RTN_QTY NUMBER,
RTA_RTN_RCPT_SCAN VARCHAR2(1 BYTE),
RTA_RTN_REFUND_AMT NUMBER(9,2),
RTA_RTN_TYPE_CODE VARCHAR2(4 BYTE),
RTA_RTN_WITH_RCPT VARCHAR2(1 BYTE),
RTA_RTN_COUNT INTEGER,
SDEDVAL1 VARCHAR2(50 BYTE)
)--sample data
REX_SEQ_NBR,REVISION_NUMBER,DAY,RESA_TRAN_SEQ_NO,BUSINESS_DATE,TRAN_SEQ_NBR,ORG_NUMBER,STORE_NUMBER,TRAN_DATE,TERMINAL_NUMBER,
TRAN_NUMBER,TRAN_TIME
478,1,11,12024005,6/11/2012,,1,692,6/11/2012,155,5,6/11/2012 12:57:17 PM,
479,1,11,12024006,6/11/2012,,1,692,6/11/2012,155,6,6/11/2012 2:01:51 PM,
480,1,11,12024007,6/11/2012,,1,692,6/11/2012,155,7,6/11/2012 2:47:10 PMAssuming that SomeJavePgm is a Java stored function (not a Java program running outside the database) and that it takes as a parameter whatever data type CUST_ID is in TABLE_A (hopefully RAW but potentially VARCHAR2) and returns a string, you would call it just as you would a PL/SQL stored function
INSERT INTO table_b( cust_id, <<other columns>> )
SELECT SomeJavaPgm( a.cust_id ), <<other columns>>
FROM table_a aIf SomeJavePgm is not a Java stored procedure, calling it from PL/SQL becomes much more complicated. You would need whatever machine hosts this program to expose an appropriate API (for example, a web service interface) that you could invoke via UTL_HTTP). You'd need to tell us what that API was, however.
Justin -
How to execute unix command from the Java program running on Windows
Hello,
I need to
1. Execute a unix shell script from a Java program running on the Windows.
2. I also need to capture the output of this shell script in my program.
Please suggest me how to achieve this.
Thanks in Advance.Hi...
Something is missing here
If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
You can test this using telnet tool on windows
just type on command prompt
telnet <ip of the unix pc> <port number this case 23>
you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant -
How to run a cygwin.bat from a java program?
Can you please let me know how to run a cygwin.bat file from a java program and to give commands through java program. I have a program to run .exe files, but when I do the same for the cygwin.bat it doesnt work. In task mgr a BASH and a cmd.exe is running. Please help me on this & bit urgent. Thanks in advance!
Can you please let me know how to run a cygwin.bat
file from a java program and to give commands through
java program. I have a program to run .exe files, but
when I do the same for the cygwin.bat it doesnt work.Of course not. .bat files are no native executables. You need to open a shell first, like "cmd /c cygwin.bat ..."
& bit urgent. Thanks in advance!If I had read this earlier I wouldn't have replied. Why exactly is your time worth more than anybody else's? -
How to read files on server from a java program?
Hello,
I am fairly new to JSP programming. I have an issue with reading files. I am trying to call method of a normal java file from a jsp program. The method I am trying to call does some IO operation on Files. I have the files in the same directory as my class files on server that is in WEB-INF/classes folder. In my java program, I am giving just the file name to open because the files and the classes are in the same directory. But this is not working.
What exactly should I do to read a file from a java program, that is running on the server?
Any help is appreciated.
Thanks,
KrishnaString realFilePath = application.getRealPath("/WEB-INF/myFile.txt");
File fileToOpen = new File(realFilePath);
out.println(fileToOpen.getAbsolutePath() + ": exists? " + fileToOpen.exists());in this case "application" is a reference to the ServletContext.
It is an implicit variable in a JSP. In a servlet:
ServletContext application = getServletConfig().getServletContext(); -
Calling servlet from a java program
Hi
I need to call a servlet's doPost() method from a java program. I have a specific situation, where I need to call servlet from a java program. DUring this call I need to pass a file and two string to the servlet. Servelt after receiving the file and string uploads the file to the server at a specified location. I am stuck up as how to call servlet from a java program instead of a HTML or JSP.
Can anyone help me to start with this.
any suggestion is welcome.You have to establish a URLConnection with servlet from your java program.
URL servletURL = new URL("http://localhost:8080/Myservlet?str1=abc&str2=def");
URLConnection servletConnection = servletURL.openConnection();you can get the objectOutputStream
ObjectOutputStream oos = new ObjectOutputStream (servletConnection.getOutputStream());
oos.writeObject(your file object);-------------------------------------------------
In the servlet u can get the strings using request.getParameter("str1");
In the servlet u can get the strings using request.getParameter("str2");
file = new ObjectInputStream (request.getInputStream()).readObject()a lot of resources are available on this ...
hope this helps :) -
Cannot call ANY stored functions from my Java program
My problem is that I cannot call ANY stored procedure from my Java
program. Here is the code for one of my stored procedures which runs
very well in PL/SQL:
PL/SQL code:
CREATE OR REPLACE PACKAGE types AS
TYPE cursorType IS REF CURSOR;
END;
CREATE OR REPLACE FUNCTION list_recs (id IN NUMBER)
RETURN types.cursorType IS tracks_cursor types.cursorType;
BEGIN
OPEN tracks_cursor FOR
SELECT * FROM accounts1
WHERE id = row_number;
RETURN tracks_cursor;
END;
variable c refcursor
exec :c := list_recs(11)
SQL> print c
COLUMN1 A1 ROW_NUMBER
rec_11 jacob 11
rec_12 jacob 11
rec_13 jacob 11
rec_14 jacob 11
rec_15 jacob 11
Here is my Java code:
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
class list_recs
public static void main(String args[]) throws SQLException,
IOException
String query;
CallableStatement cstmt = null;
ResultSet cursor;
// input parameters for the stored function
String user_name = "jacob";
// user name and password
String user = "jnikom";
String pass = "jnikom";
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
try { Class.forName ("oracle.jdbc.driver.OracleDriver"); }
catch (ClassNotFoundException e)
{ System.out.println("Could not load driver"); }
Connection conn =
DriverManager.getConnection (
"jdbc:oracle:thin:@10.52.0.25:1521:bosdev",user,pass);
try
String sql = "{ ? = call list_recs(?) }";
cstmt = conn.prepareCall(sql);
// Use OracleTypes.CURSOR as the OUT parameter type
cstmt.registerOutParameter(1, OracleTypes.CURSOR);
String id = "11";
cstmt.setInt(2, Integer.parseInt(id));
// Execute the function and get the return object from the call
cstmt.executeQuery();
ResultSet rset = (ResultSet) cstmt.getObject(1);
while (rset.next())
System.out.print(rset.getString(1) + " ");
System.out.print(rset.getString(2) + " ");
System.out.println(rset.getString(3) + " ");
catch (SQLException e)
System.out.println("Could not call stored function");
e.printStackTrace();
return;
finally
cstmt.close();
conn.close();
System.out.println("Stored function was called");
Here is how I run it, using Win2K and Oracle9 on Solaris:
C:\Jacob\Work\Java\Test\Vaultus\Oracle9i\FunctionReturnsResultset>java
list_recs
Could not call stored function
java.sql.SQLException: ORA-00600: internal error code, arguments:
[ttcgcshnd-1], [0], [], [], [], [], [], []
at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:889)
at
oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:490)
at
oracle.jdbc.driver.OracleStatement.getCursorValue(OracleStatement.java:2661)
at
oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:4189)
at
oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:4123)
at
oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:541)
at list_recs.main(list_recs.java:42)
C:\Jacob\Work\Java\Test\Vaultus\Oracle9i\FunctionReturnsResultset>
Any help is greatly appreciated,
Jacob NikomThank you for your suggestion.
I tried it, but got the same result. I think the difference in the syntax is due to the Oracle versus SQL92 standard
conformance. Your statament is the Oracle version and mine is the SQL92. I think both statements are acceptable
by the Oracle.
Regards,
Jacob Nikom
Maybe you are looking for
-
How to count words in a text ?
Hi all, can anyone show me how to count the number of words in a text. thank in advandce, Toan.
-
Diffrence between File Transport and CTS+ Transport in PI
Hi Guys, Can you please explain me the diffrence between File Transport and CTS+ Transport in PI. What are the advantages of CTS+ Transportation over FILE Transportation... Thanks, Siva...
-
Passing Select-Option to OO method via parameter list
Is it possible to pass a reference to a select-option through the parameter list of a method such that the parameter can be used in a "where clause" using the conventional "IN" operator? If so, how should the parameter be typed? Thanks in advance,
-
Abap - incompatible type error
Hi Experts, I got the requirement to change spell_amount function module into Z_SPELL_AMOUNT Function module. Sap has givin some modifications in spell_amount function module. so i have done those changes in Z_SPELL_AMOUNT FM After changing the code.
-
Hi All, I am making a swing application i want that when my applicatio.zip file extracted an automatic shortcut at desktop gets created whose target is pointed to my application.bat file. Please Help, Thanks