Using command prompt through java, help please!
Hi,
What I am trying to do is find all the processes running onthe computer using java. Normally, I would do this (without java) by opening a command prompt window, typing in tasklist and see all the running processes. I have tried to to do the same thing using java, but so far have been unsucsessful. Here is my code:
import java.io.*;
public class Main {
static DataOutputStream output;
static DataInputStream input;
static String app="cmd.exe";
static String command="tasklist";
static String message="";
public static void main(String args[])throws Exception{
Process process = Runtime.getRuntime().exec(app);
output=new DataOutputStream(process.getOutputStream());
input=new DataInputStream(process.getInputStream());
output.write(command.getBytes());
byte[] b=new byte[input.available()];
input.readFully(b);
message=new String(b);
System.out.println("Message: "+message);
System.out.println(!message.equals(""));
System.out.println(message!=null);
System.out.println("Finished Program");
}And this program prints the output (with no exceptions):
Message:
false
true
Finished Program
I appreciate any help in fixing my program...
DevRocks_Java wrote:
static String app="cmd.exe";
static String command="tasklist";
Process process = Runtime.getRuntime().exec(app);
output=new DataOutputStream(process.getOutputStream());
input=new DataInputStream(process.getInputStream());What do you expect it to do? You are only telling it to open a console window, nothing more.
if you can type tasklist at the run option, then you should be able to just substitute command in for app in your exec.
Similar Messages
-
Using command prompt with Java
I am trying to use command prompt within a java program and I can't figure out how to enter commands from java. I know how to start up command prompt but can someone guide me on a way to actually enter commands into the command prompt? Thanks.
The Java� Tutorial - Lesson: Basic I/O
~ -
Manipulating Windows command prompt through Java
I am wondering if there is any way to manipulate simple Windows command prompt commands like color, cd, dir, cls through a java application. Any help or informative redirection would be much appreciated.
BinaryBurnout wrote:
I am wondering if there is any way to manipulate simple Windows command prompt commands like color, cd, dir, cls through a java application. Any help or informative redirection would be much appreciated.Realize that the Windows command prompt is an application (cmd.exe), and those commands are specific to that application. -
After updating to latest iOS my iphone 4 is mute, at start the other party couldn't hear me, now I cant hear anything not even the ringing tone. This happens only if make regular calls through my carrier. If use viber all ok. Help please?
I read on another discussion that sucking air out of the headphone slot works, I tried it and guess what, it worked.......weired....apparently something to do with moisture accumulation....!!!!!!
-
Using command prompt for help generating
Hi all!
Can I use command prompt for generating webhelp instead of
RoboHelp HTML environment?
thank youSee this recent post.
Click
here. -
Running a Program in JDeveloper using Command Prompt
Hi,
I downoladed Oracle JDeveloper 10g. I had written a simple java class called Echo. java. I want to run the file using command prompt. My JDK has the following path:
F:\Sowmya
My java file has the following path:
F:\Sowmya\jdev\mywork\1\1\src\pkg1
So, in order to compile the file, I gave the following command:
F:\Sowmya\jdk\bin>javac F:\Sowmya\jdev\mywork\1\1\src\pkg1\Echo.java
It worked and the Echo.class file was created.
But, when I tried to run the file using the following command,
F:\Sowmya\jdk\bin>java F:\Sowmya\jdev\mywork\1\1\src\pkg1\Echo
Iam getting the following error:
Exception in thread "main" java.lang.NOClassDefFoundError: F:\Sowmya\jdev\mywork\1\1\src\pkg1\Echo
This didnt work either:
F:\Sowmya\jdk\bin>java F:\Sowmya\jdev\mywork\1\1\classes\pkg1\Echo
Iam getting the same error.
Can any one please help me regarding this.
Thank you,
Sowmya.Yes, my class contains a main. It runs if I click run in JDeveloper. But, there is no output displayed. The following is the code:
public class Echo {
public static void main (String[] args) {
for (String s: args) {
System.out.println(s);
} -
How to print pdf file in SQL Server Reporting services report using command prompt?
Is there a way to automatically print a SQL Server Reporting services report on command prompt? For eg: We can save a pdf file using rs.exe utility. I want to print a pdf using rs.exe utility. Is it possible? I don't want to install any 3rd party software.
Thanks Simon for replying to my question.
In oracle form, there is oracle command to print the report from command prompt with the help of rwrun.exe
e.g: rwrun.exe REPORT="D:\Test\REP_25\MLA.REP" DESNAME="testprinter" DESTYPE="PRINTER" P_FORMNAME="MLA.FMX" P_SPRACHE="E" P_SPRACHE_NR2="1" P_WHERE_BEDINGUNG="order by land_nr" USERID="test/test.world" PSV_NAME="PSV_DEMO" PSV_JOB_ID="PS$9583" RECURSIVE_LOAD="NO"
BATCH="YES" NONBLOCKSQL="NO" ARRAYSIZE="1" PARAMFORM="NO" ERRFILE="c:\temp\psv16.tmp"<
and to save the report we just need to change DESNAME="c:\temp\OC_100001349.pdf" DESTYPE="FILE" in above command instead of DESNAME="testprinter" DESTYPE="PRINTER".
DESNAME and DESTYPE are the input parameters of the respective report.
In SSRS, we can run the file from the command prompt and save it.
rs -i "C:\Users\pujarswa\Documents\reports\new\LoadReport.rss" -s ww2004760:80/ReportServer_MSSQL -v fileName="C:\Users\pujarswa\Desktop\TipsReportLoad.pdf"
-v reportPath="/TipsReport/LoadListTabular" -t -v format="PDF" -v LandNr=4 -u ap\swati -p test@# -e Exec2005
But we cannot use same command for printing as you said we need to create another script for printing files.
I have gone through the links but I dont want to use Adobe Acrobat Reader exe for printing because client it may not have Adobe Acrobat Reader on their machine.
Also I want to pass a input parameter as type="Printer" to my report which will print directly for me and same I can acheive in command prompt passing type="Printer" fileName="C:\Users\pujarswa\Desktop\TipsReportLoad.pdf" -
How to use addKeyListener in a program running using command prompt
Does anyone have any idea how to add the addKeyListener to a program running using command prompt.
Let me explain how the program run.
The program is start and accept call from other program. But from time to time, I need to issue some command by pressing the keyboard, let say, ESC is closed the program, F1 is showing the stated. F2.... (This is all need to run in the command prompt windows)
My problem is this program does not have any gui interface, so how can it be added?
i do it this way
public void key(){
addKeyListener(this);
But it have compile error.
mainServerImpl.java:87: cannot resolve symbol
symbol : method addKeyListener (mainServerImpl)
location: class mainServerImpl
addKeyListener(this);
I did implement KeyListener. But just don't know how to solve this error.
can anyone tell me how to solve it or point me a source that can help.
Thank in advance!
Regards,
Tai TanWrite your own Thread, to do this:
public class KeyThread extends Thread {
public void run {
while(true) {
int i = System.in.read();
if(i == 123) {
break; // to stop the thread
// in your main:
Thread keyThread = new KeyThread();
keyThread.start(); // calls run() of the thread -
How to compile & run using command prompt
Hi all,
I have a java application consisting of 3 packages & a jar file in the following hierarchy:
-Project
-classes
-src
-package1
-package2
-package3
-file.jar
The main class exists in package2 and uses classes within file.jar
I want the steps to compile and execute the project using command prompt in windows such that the generated classes will be saved in the classes directory
Can anyone help?
Thanx in advanceHey,
If your source(*.java) files are in src folder and ur currnet directory is project
and you want all your class files to be classes folder then you can try this :
c:\project>javac -cp src\file.jar -d classes\ src\*.javaAssuming that your file.jar file is in src folder.
The above command will set the classpath to src\file.jar (-cp src\file.jar)
-d classes\ - will generate all your class files with package hierarchy if any into classes directory.
src\*.java - specifies the files to be compiled.
Hope this helps. -
Uninstalling bulk dll's from gac folder at one time using command prompt
Hi All,
I need to unistall bulk dll's at a time from the GAC folder using command prompt ,can any one suggest how to do this.Hi,
1. Create a batch file as "Uninstall.bat".
2. Edit this file and copy the below statements in it:
gacutil.exe /uf DLL1
gacutil.exe /uf DLL2
gacutil.exe /uf DLL3
gacutil.exe /uf DLL4
gacutil.exe /uf DLL5
replace DLL1 to DLL5 with your actual DLL names, which you want to uninstall.
3. Open Visual Studio Command Prompt as Administrator.
4. Browse to the location where you have placed the above batch file.
5. Run the batch file.
Hope this will help.
HTH,
Sumit
Sumit Verma - MCTS BizTalk 2006/2010 - Please indicate "Mark as Answer" or "Mark as Helpful" if this post has answered the question -
Can i login to essbase console by using command prompt
Hi All,
Is thr any possiblity to login in to essbase console by using command prompt
normally we login to console and will give credentails and login as same way can we do from command prompt??
Thanks in advance
Regards,
SMHello ,
You can check the login through the Essbase command utility.
go to command prompt . type - essmsh
then you will be able to see MaxL prompt
enter the command login username password;
you can use this utility to load data , import export running calc etc...
Thanks,
KKT -
How to run ODI scenario using command prompt
Hi expets
Please let me know if we can run ODI scenario using command prompt or any way other than operator.
Regards
JanakiramGo to <ODI_HOME>/oracledi/bin in command prompt and invoke startscen command with teh below parameters.
Edited by: Guru Sankar on Feb 28, 2011 4:19 PM -
Changing java version from 4 to 5 using command prompt
My default java version is 1.4 . I want to change to jdk 5 for a particular command prompt session alone. i used the following commands
java - versionjava version "1.4.2_07"
set path = C:\java\jdk150_06\bin;%path%.C:\bea92\jdk150_04\bin;C:\WINNT\system32;C:\WINNT;
java - versionjava version "1.4.2_07"
The version still points to 1.4. What is the method to change it from 1.4 to 1.5 ?
Thanks..Rohiini wrote:
My default java version is 1.4 . I want to change to jdk 5 for a particular command prompt session alone. i used the following commands
java - versionjava version "1.4.2_07"No, that will say
Unrecognized option: -try
java -version
set path = C:\java\jdk150_06\bin;%path%That will not set anything, try
set path=C:\java\jdk150_06\bin;%path%or just
path=C:\java\jdk150_06\bin;%path% -
Error when executing scenario use command prompt - startscen
Hi All,
Anyone know how to solve this error? I get this error message when I execute command prompt: startscen scenarioName version001 contextDevelopment "-v=2"
The error message is:
java.lang.NullPointerException
at com.sunopsis.g.a.f.b(f.java)
at com.sunopsis.tools.core.SnpsStringTools.a(SnpsStringTools.java)
at com.sunopsis.dwg.DwgObject.snpsDecypher(DwgObject.java)
at com.sunopsis.dwg.DwgJv.treatCmd(DwgJv.java)
at com.sunopsis.dwg.DwgJv.main(DwgJv.java)
at oracle.odi.Agent.main(Agent.java)
I use JDK version 1.4.
Thanks in advance.
Regards,
SumardiHi Sumardi,
Trying to help you,
Please cross check the repository configuration information in ODIPARAM.BAT file.
Thanks,
G -
How to get the drive letter of a Volume using command prompt
Using windows command line tools i want to get the drive letter of a volume, by specifying its volume number.
For example i have a HDD with 2 volumes: Volume-0 and Volume-1
I want to set a Variable say 'Letter'=<Drive Letter> such as
SET Letter=<Command> <Volume Number>
Is there any command which can do this for me...
Thanks...Hi,
You can use the diskpart tool to assign a drive letter to the drive by specifying the volume's number.
1.Open Command Prompt.
2.Type:diskpart
3.At the DISKPART prompt, type:list volume
Make note of the number of the simple volume whose drive letter you want to assign, change, or remove.
4.At the DISKPART prompt, type:select volume n
Select the volume, where n is the volume's number, whose drive letter you want to assign, change, or remove.
5.At the DISKPART prompt, type one of the following:assign letter=L
Where L is the drive letter you want to assign or change.
For more detailed information, you could refer to the article below:
Assign, change, or remove a drive letter
https://technet.microsoft.com/en-us/library/cc757491(v=ws.10).aspx
Best Regards,
Mandy
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]
Maybe you are looking for
-
Hi, I'm new to the Mac experience and I'm trying to set-up file sharing with my MacBook and PC and I can't figure it out. I've tried entering the PC's IP address through the Finder - Connect to Server, but I can't get it working. I would appreciate a
-
so, when I first got the computer I installed panther and everything was fine until the computer went to sleep. I woke it up and the display was sort of fuzzy and it got worse and worse. I restarted the computer and it was fine. I tried to find out w
-
gc_w01_enu_nb.exe extracts to 100% but setup fails instantly in winxp pro I'm trying to install the full featured driver for my psc-1315xi on two WinXP Pro PCs. The first one worked perfectly. On the second one, when I run the downloaded exe, I get t
-
When search help is executed initially i want to display a screen for selection criteria and values have to be displayed how we can do this one?
-
Initial stock quantities posting
Hi, I am trying to get a valuation of the initial stock entered on our system for our accountant. In trying to do this I have been looking at the journal entries in the Stock account in chart of accounts and see that the 2 lines on each of the initia