简体   繁体   中英

How to initialize CommandLine class?

I am working with this command Line class of org.openqa.selenium.os package and wanted to execute a dir command get the output to my java code.

here is, what i have just tried,

String[] cmds={"date","dir"};
CommandLine cl=new CommandLine(cmds);
cl.execute();
System.out.println("The out put is "+cl.getStdOut());

i get this,

Exception in thread "main" java.lang.NullPointerException: Unable to find executable for: date
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:236)
at org.openqa.selenium.os.UnixProcess.<init>(UnixProcess.java:61)
at org.openqa.selenium.os.CommandLine.<init>(CommandLine.java:47)

What i did wrong ? i jsut googled but no luck. you can also check this to know what CommandLine class does.

I am using Windows XP 32 bit and getting the same exception for all the commands.

In computing, CLS (for clear screen) is a command used by the command line interpreters COMMAND.COM and CMD.EXE on DOS, OS/2 and Microsoft Windows operating systems to clear the screen or console window of commands and any output generated by them.

see http://en.wikipedia.org/wiki/CLS_(command)

if you run cmd -c cls you will get your desired result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM