java “cscript //NoLogo”代表什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11827177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What "cscript //NoLogo" stands for?
提问by Sarsur.A
This is a java program code that runs the Notepad program and pastes a specific text stored in this program itself....
这是一个java程序代码,它运行记事本程序并粘贴存储在该程序本身中的特定文本....
I was wondering if you can explain me the String vbs
value, and also the File file
, and the ("cscript //NoLogo " + file.getPath())
in the Process p
.
If you are as generous, then please explain me the whole code.
我在想,如果你能解释一下我的String vbs
价值,也File file
和("cscript //NoLogo " + file.getPath())
在Process p
。如果你这么大方,那么请向我解释整个代码。
I'm a beginner in Java, well not exactly but if u wanna judge from 0 to 10 i would be 1.5/10
我是 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();
}
}
回答by ruffin
Though this question wasn'tprimarily about cscript //NoLogo
, regardless of its title, it still googles well for that phrase, so let's answer that in too much detail too.
虽然这个问题主要不是关于cscript //NoLogo
,不管它的标题是什么,它仍然可以很好地搜索该短语,所以让我们也详细回答一下。
I'm not sure why they call it a "logo", but it's exactly what you might think from the built-in help @MByD displayed. But in the interest of over-completeness...
我不确定为什么他们称它为“徽标”,但这正是您从显示的内置帮助 @MByD 中可能想到的。但是为了过度完整性......
C:\prompt>cscript spam.js
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\prompt>cscript //NoLogo spam.js
C:\prompt>
So if you're piping output and don't want all that Microsoft boilerplate, \\Nologo
-ify it.
因此,如果您正在管道输出并且不想要所有 Microsoft 样板文件,\\Nologo
请对其进行验证。
C:\prompt>cscript spam.js > out.txt
C:\prompt>more out.txt
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\prompt>cscript spam.js //NoLogo > out.txt
C:\prompt>more out.txt
C:\prompt>
(spam.js
has var spam = "spam";
in it.)
(里面spam.js
有var spam = "spam";
。)
And, wow, that is a horribly convoluted way to get text into Notepad. I'm guessing it's more about teaching how to write to a file and exec
a command from Java, perhaps?
而且,哇,这是一种将文本输入记事本的极其复杂的方式。我猜这可能更多是关于教授如何exec
从 Java写入文件和命令?
回答by MByD
What you basically do is:
你基本上做的是:
- Create a String that contains a script (
String vbs = ...
) - Write it to a file (
File file = File...
tofw.close()
) - Execute this script in a separate process by invoking cscript (
Process p = Runtime.getRuntime().exec(...)
)
- 创建一个包含脚本的字符串 (
String vbs = ...
) - 将其写入文件 (
File file = File...
tofw.close()
) - 通过调用 cscript (
Process p = Runtime.getRuntime().exec(...)
)在单独的进程中执行此脚本
Regarding cscript //NoLogo
, this has pretty much nothing to do with Java, this is a windows command:
关于cscript //NoLogo
,这与 Java 几乎没有关系,这是一个 windows 命令:
C:\Documents and Settings\bsharet>cscript
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
Usage: CScript scriptname.extension [option...] [arguments...]
Options:
//B Batch mode: Suppresses script errors and prompts from displaying
//D Enable Active Debugging
//E:engine Use engine for executing script
//H:CScript Changes the default script host to CScript.exe
//H:WScript Changes the default script host to WScript.exe (default)
//I Interactive mode (default, opposite of //B)
//Job:xxxx Execute a WSF job
//Logo Display logo (default)
//Nologo Prevent logo display: No banner will be shown at execution time
//S Save current command line options for this user
//T:nn Time out in seconds: Maximum time a script is permitted to run
//X Execute script in debugger
//U Use Unicode for redirected I/O from the console