How can I pass system commands from a java program? Urgent!
hi,
I have been trying this out since a long time. How do I send system commands to command.com or cmd.exe from a java program and an output of the executed command back to the java application.
If u have any idea, or have any information about the kind os application reply back.
Thanks
Deepa Datar
This is the code which I tried, but it displays only the title of MS-DOS, something like " Microsoft Corp...etc ". But doesn't take any input, and the subprocess(cmd.exe) hangs.
import java.io.*;
public class cmddemo2
public static void main(String arg[])
try
System.out.println("cmd");
Process p=Runtime.getRuntime().exec("cmd.exe");
DataInputStream din=new DataInputStream(p.getInputStream());
DataOutputStream dout=new DataOutputStream(p.getOutputStream());
System.out.println("after streams");
String s;
dout.writeChars("type cmddemo2.java");
while((s=din.readLine())!="\n")
System.out.println(s);
dout.writeChars("dir");
String s1;
while((s1=din.readLine())!="\n")
System.out.println(s1);
System.out.println("over");
catch(Exception e)
{ System.out.println("Exception : "+e);
Similar Messages
-
How to run a openssl command from a java program
Hi All
Please suggest on how to run a openssl command from a java program.
I am using this
Runtime runtime = Runtime.getRuntime();
runtime.exec("openssl pkcs8 -inform der -nocrypt test.der result.pem");
This is suppose to take test.der as input and create result.pem.
There are no errors but the file result.pem isnt created.
Thanks in AdvanceFirst off is that openssl command correct? Should it be this instead:
openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
After that.....
runtime.exec creates a Process object. If you do this:
Process openssl = runtime.exec("....")
then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
M -
How can I get the events from a java program?
I want to make a monitor to watch a java program.How can I get the events from the GUI of this program some as mouse cliking, keyinput. So I can watch these in my monitor.
ThanksHi,
To put a monitor to the events occuring in the GHUI u need to register required components with the appropriate EventListeners.
Liek if u want to get notified when a mouse is clicked, then u need to add The MouseListener to the component which u want to be monitored.
Say
myFrame which is the JFrame object which shuld be monitored for the events.
Then in ur program u have to add following code
myFrame.addMouseListener( someObectReference );
Here the someObjectReference should be an instance to a concrete class ..i.e. U write a class like the following
public class MyMouseListener implements MouseListener {
// override the followig methods
public void mouseClicked(MouseEvent me){ sop("MOUSE CLICKED ON THE FRAME");}
public void mousePressed(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
If u dont want to use another class for listening to the events. Then u can make teh current class monitor the events. To do so ur class should implement the appropriate listener and should override the required methods.
and u should say myFrame.addMouseListenet( this );
thats it -
How can I make a screensaver from a Java program?
Hi!
I've made a Java program works as a screensaver, and I've grouped all files into a jar file. How can I make a screensaver from this jar file?
Thanks.check https://jdic.dev.java.net/documentation/incubator/screensaver/
- I think it's still in development, but it's something... -
How can I pass the photos from one iphone to another?
how can I pass the photos from one iphone to another?
Use the Beaming feature. See the info at the ? In iPhoto for iOS.
-
How can i pass the music from my ipod touch to my mac
how can i pass the music from my ipod touch to my mac
If the music on the iPod was purchased through iTunes you can try Transfer Purchases.
Connect the iPod to the Mac and launch iTunes. Right click on the iPod name on the left side of the iTunes window under the devices heading and select Transfer Purchases. That should transfer the music into the iTunes library on the Mac.
iTunes Store: Transferring Purchases -
How to execute Operating System commands from Stored procedure.
Any help on how to execute Operating System commands from stored procedures will be appreciated.
Nanditha.Search the forums for 'External Procedure' and you will find example code that has been posted before.
-
How can I stop my Air from moving my programs that I leave open to other windows where I didn't leave them?
Try toggling this preference (circled):
-
How:Execute OS commands from a Java program
hi,
is it possible to execute an OS command from a java program, as in C/C++? if yes, plz give the details.
thanxIn the future try searching the forum before posting. Using keywords like "execute os commands" would lead you to several postings on this topic.
Note the keywords where taken directly from you subject line. With practice you learn which keywords to use to yield the best search results. -
How to call j2me emulator instance from a java program?
hi,
how to call j2me emulator instance from a java program?
i tried public void startApp(){
try{
platformRequest("tel:+5550000");
}catch(Exception e){
e.printStackTrace();
from a j2me midlet itself,
but it gave illegal access exception.
do i need any hardware phone connected to my pc?
please help.http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
import java.util.*;
public class OpenExplorer{
public static void main(String args[]){
new OpenExplorer();
public OpenExplorer(){
try{
String command = "explorer C:";
// or String command = "cmd /c explorer C:";
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(command);
int exitVal = process.waitFor();
System.out.println("Exit Value: " + exitVal);
} catch(Exception e){
e.printStackTrace();
} -
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 display a oracle table from a java program?
How to display a oracle table from a java program.
Hello friends, I have written a Java program, using oracle 10g as backend.
I want to display a oracle table as output. Im not getting how to display oracle table as a output table.. Pls help me
Thank youjayanthds, you're not going to get a satisfactory
answer to this here. it's too big a task to justbe
quickly outlined in a forum - the reply "all youneed
to do is to query you table and return it asJTable"
is worthless, for example, since the solution to
any problem can be distilled to such a
soundbite, if need be. doesn't make the solutionany
simpler
essentially you're asking "how do I write adatabase
application?". all you'll get is snippets of code
that, when fitted together, will eventually helpyou
do this, but you'll spend days and days comingback
saying "right, I've done that, now what?" until
either you or the forum gets frustrated with the
whole affair and the process stops
there are entire books written about this subject,
and countless tutorials and guides on theinternet.
you're better off going down that routehehehe.well, it's true! I used to have a manager that would outline the solution to a problem in a few lines of pseudocode, and then firmly believe that the actual solution would be just as brief and simple. shame his pseudocode included such lofty abstractions as "reformat all data" -
How can I pass Global Variable from Page1 to Page2
I have the following senario.
Pag1 - report is based on following PL\SQL
declare
g1 varchar2(100);
begin
g1 = select * from emp where dept = 10;
return g1;
end;
Now I have Page2 - based on following PL\SQL
declare
g2 varchar2(100);
begin
g2 := g1; -- here i want to use variable g1???
return g2;
end;
My question is - How can I use variable g1 from P1 in my new page P2.
Thanks,
DeepakHi Andy,
Thanks for the clarification.
I did exactly the same, created a new Region with HTML (PL\SQL) and got the output. it was fine.
Now when I am using exactly the same code in a Report (PL/SQL function returning a SQL Query), I am getting the following error.
DECLARE
g VARCHAR2(100);
BEGIN
g := 'This is a test string';
APEX_UTIL.SET_SESSION_STATE('G_SQL_STRING', g);
htp.p(v('G_SQL_STRING'));
END;
ERR-1002 Unable to find item ID for item "FLOW_SECURITY_GROUP_ID" in application "4000".
ERR-1002 Unable to find item ID for item "G_SQL_STRING" in application "4000".
I am doing the same thing, nothing changed....only difference is in 1st case I am using HTML (PL\SQL) Region and in 2nd case using the REPORT Region (PL/SQL function returning a SQL Query)
thanks,
deepak -
How to: execute operating system commands from PL/SQL
System: IBM pSeries AIX
Oracle: 11g Enterprise
Is there a quick way to execute operating system commands from PL/SQL?
Without creating a JAVA class....
I need to execute a Loader script.
I want to do this from within PL/SQL.
I need to to do 4 things.
Three require SQL scripts.
The fourth is SQL*Loader.
The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
Is there way to do all this from within ONE PL/SQL SCRIPT ??
Just let me know.Is there a quick way to execute operating system commands from PL/SQL?
NO
Without creating a JAVA class....
I need to execute a Loader script.
I want to do this from within PL/SQL.
WHY ON EARTH, such action will create a new connection and become a resource hog?
I need to to do 4 things.
Three require SQL scripts.
The fourth is SQL*Loader.
The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
Which is perfect for the purpose.
Is there way to do all this from within ONE PL/SQL SCRIPT ??
Just let me know.
NO, there is NOT. Nor should there be. Why create unstable ineffcient Mickey Mouse systems, glued together by hacking?
Sybrand Bakker
Senior Oracle DBA -
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
Maybe you are looking for
-
So how does this work on Mountain Lion? I cannot seem to ignore the iTunes 11 updates, which now seem to appear every 5 minutes!!
-
Foolishly have forgotten cloud password and security questions. It offers to email the password but as there is no password on the iCloud it won't let email thru, which creates a perpetual circle of no emails. Help please
-
Vim mode in Emacs (no editor war)
I've been using vim for some time now and I really appreciate the different modes and key bindings. I've experimented a little with emacs and I really like it as a development environment and its flexibility and extensibility, but so far I don't real
-
MARA-MFRNR display field in material master
hi MARA-MFRNR is not displaying in material master purchasing tab view. please guide thaks
-
Search Results Weight By File Type?
We are crawling a series of folders using the NT CWS. Some folders contain primarily HTML content while others contain binaries (PDF, DOCs). The folders are split into "Web Content" and "Publications" at the root -- so they are already segregated by