- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我找不到任何地方可以具体解释 Process exec(String[] cmdarray)
的 String[] cmdarray
中可以存储什么内容。方法。我找到了一些地方 cmdarray
来存储数组命令或文件位置和远程服务器名称。所以我想知道我们到底可以在 String[] cmdarray
中存储什么?
最佳答案
数组的第一个元素是命令,例如cmd
。其他的都是论证。例如:
try {
Process p = Runtime.getRuntime().exec(new String[] {"cmd", "/c", "echo", "This", "is", "an", "argument"});
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s;
while((s = reader.readLine()) != null) {
System.out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
}
这里“/c”
,“echo”
,“这个”
,"is"
,"an"
和 "argument"
都是命令 cmd
的参数。输出为:
This is an argument
如果要运行多个命令,则必须使用双“&”号来指示另一个命令正在启动:
try {
Process p = Runtime.getRuntime().exec(new String[] { "cmd", "/c", "echo", "This", "is", "an", "argument",
"&&", "echo", "this", "command", "snuck", "in" });
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s;
while ((s = reader.readLine()) != null) {
System.out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
}
这里每个命令都被发送到 cmd
。我并不肯定,但我相信你必须开始一个新的流程来向其他地方发送命令。输出为:
This is an argument
this command snuck in
阅读此内容以获取更多信息:https://stackoverflow.com/a/18867097/5645656
关于java - 我们到底可以在 Process.exec() 的字符串数组中存储什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48011611/
这对你们来说可能很简单,但由于我是java新手,所以我想知道实际上什么是 接下来的部分会发生什么? if (args.length > 0) { file = args[0]; } publi
在我的 View Controller 中,我将 UITapGestureRecognizer 添加到 self.view。我在 self.view 之上添加了一个小 View 。当我点击小 View
我今天尝试从 Obj-C 开始并转到 Swift,我正在阅读文档。我试图在 Swift 中创建一个简单的 IBOutlet,但它不断给我这些错误。 View Controller 没有初始化器 req
我正在尝试使用 VIM 完成(字典和当前缓冲区),但我遇到了问题?和 !在方法名称的末尾。我能以某种方式向 vim 解释方法名称(基本上是单词)最后只能有它,而且只有一个,即 method_name
我是一名优秀的程序员,十分优秀!