0

I am using the following code to try and retrieve information from the Windows Task Manager:

Runtime.getRuntime().exec("tasklist /v /fi");

When I enter "tasklist /v /fi" into windows CMD it works, but in java it gives me the error that the file path could not be found.

0

1 Answer 1

1

Use String array to run command with multiple options.

Runtime.getRuntime().exec(new String[]{"tasklist","/v","/fi"});
Sign up to request clarification or add additional context in comments.

5 Comments

Like this: Runtime.getRuntime().exec(new String[]{"tasklist/v"}); because I have tried that and I still get the error.
Can you help me with one more thing I am creating the String Array as follows: String[] tempString = new String[]{"tasklist", "/v ", "/fi ", "\"Imagename eq javaw.exe"\""}; in the last part I need Imagename eq jawax.exe surrounded with "" (Quotation Marks) the code I am using isn't doing it though.
Yes the last paramater is: Imagename eq javaw.exe. all together the problem is I need it to be surrounded by "" quotation marks for the cmd to read it and the code I am using is suppose to do that but it is not.
Can you try single quots?
Hi, ok I figured it out. The code I posted in the comments worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.