简体   繁体   English

如何初始化CommandLine类?

[英]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. 我正在使用org.openqa.selenium.os软件包的此命令行类 ,并希望执行dir命令将输出输出到我的Java代码。

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. 您还可以检查此项以了解CommandLine类的作用。

I am using Windows XP 32 bit and getting the same exception for all the commands. 我正在使用Windows XP 32位,并且所有命令都遇到相同的异常。

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. 在计算中,CLS(用于清除屏幕)是命令行解释器COMMAND.COM和CMD.EXE在DOS,OS / 2和Microsoft Windows操作系统上使用的命令,用于清除命令或由命令生成的任何输出的屏幕或控制台窗口他们。

see http://en.wikipedia.org/wiki/CLS_(command) 参见http://en.wikipedia.org/wiki/CLS_(命令)

if you run cmd -c cls you will get your desired result 如果您运行cmd -c cls ,将得到您想要的结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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