hi,

I want to run the command using java code

echo $PATH

I used Runtime.getRuntime().exec() for this, but it returns outputp as : $PATH.

I know I can get the value of PATH variable using System.getProperty() but I want to use particularly "echo" command.

How can I do it?

What OS are you using? Under Windows that should be
echo %PATH%

ps: Have a look at the ProcessBuilder class in Java 1.5 and later - it's intended as a better replacement for Runtime.getRuntime().exec()

Also consider...

System.out.println(System.getenv("Path"));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.