java“cscript//NoLogo”代表什么?
这是一个java程序代码,运行记事本程序并粘贴存储在此程序本身中的特定文本
我想知道你能不能给我解释一下String vbs
值,还有File file
和("cscript //NoLogo " + file.getPath())
中的Process p
。
如果你是慷慨的,那么请向我解释整个代码
我是Java的初学者,不完全是,但是如果你想从0到10判断,我会是1.5/10
import java.io.File;
import java.io.FileWriter;
import javax.swing.JTextField;
public class PasteToNotepad {
public static void main(String[] args) throws Exception {
String text = "Some text for testing.";
JTextField textField = new JTextField(text);
textField.setSelectionStart(0);
textField.setSelectionEnd(text.length() - 1);
textField.copy();
String vbs = ""
+ "Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
+ "WshShell.Run \"notepad\", 9\n"
+ "WScript.Sleep 500\n"
+ "WshShell.SendKeys \"^V\"";
File file = File.createTempFile("PrintDialog", ".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
p.waitFor();
}
}
# 1 楼答案
尽管这个问题主要不是关于
cscript //NoLogo
,不管它的标题如何,它仍然适合谷歌搜索这个短语,所以我们也来详细回答这个问题“我知道他们可能会把它叫做”MByD“,但我不知道为什么他们会把它叫做“MByD”。但出于对过度完整性的考虑
因此,如果您正在使用管道输出,并且不希望使用所有的Microsoft样板文件,请
\\Nologo
-将其加以验证(
spam.js
中有var spam = "spam";
。)而且,哇,这是一种非常复杂的将文本输入记事本的方法。我猜这更像是教你如何从Java写文件和命令
# 2 楼答案
你基本上要做的是:
String vbs = ...
)File file = File...
到fw.close()
)Process p = Runtime.getRuntime().exec(...)
)在单独的进程中执行此脚本关于
cscript //NoLogo
,这与Java几乎没有任何关系,这是一个windows命令: