windows wscript 和 cscript 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8678441/
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
Difference between wscript and cscript
提问by rashok
What is the difference between cscript and wscript? Which is best for doing Telnet and FTP automation in Windows?
cscript 和 wscript 有什么区别?哪个最适合在 Windows 中执行 Telnet 和 FTP 自动化?
回答by Ben
In Windows, an executable is either a console application or a Windows application (or a SFU or Native application, but that doesn't matter here).
在 Windows 中,可执行文件是控制台应用程序或 Windows 应用程序(或 SFU 或本机应用程序,但这在这里无关紧要)。
The kernel checks a flag in the executable to determine which.
内核检查可执行文件中的标志以确定哪个标志。
When starting using CreateProcess
WinAPI function, if it is a console application, the kernel will create a console window for it if the parent process doesn't have one, and attach the STDIN
, STDOUT
and STDERR
streams to the console.
当开始使用CreateProcess
WinAPI 函数时,如果它是一个控制台应用程序,如果父进程没有,内核会为其创建一个控制台窗口,并将STDIN
,STDOUT
和STDERR
流附加到控制台。
If it is a Windows application, no console will be created and STDIN
, STDOUT
and STDERR
will be closed by default.
如果是 Windows 应用程序,则不会创建控制台STDIN
,STDOUT
并且STDERR
默认关闭。
WSCRIPT.EXE
and CSCRIPT.EXE
are almost exactly identical, except that one is flagged as a windows application and the other is flagged as a console application (Guess which way around!).
WSCRIPT.EXE
并且CSCRIPT.EXE
几乎完全相同,除了一个被标记为 Windows 应用程序,另一个被标记为控制台应用程序(猜猜是哪一个!)。
So the answer is: If you want your script to have a console window, use CSCRIPT.EXE
. If you want it to NOT have a console window, use WSCRIPT.EXE
.
所以答案是:如果你想让你的脚本有一个控制台窗口,使用CSCRIPT.EXE
. 如果您希望它没有控制台窗口,请使用WSCRIPT.EXE
.
This also affects some behaviors, such as the WScript.Echo command. In a CSCRIPT.EXE
this writes a line to the console window. In WSCRIPT.EXE
it shows a messagebox.
这也会影响某些行为,例如 WScript.Echo 命令。在 aCSCRIPT.EXE
这将一行写入控制台窗口。在WSCRIPT.EXE
它显示一个消息框。
For your application I suggest CSCRIPT.EXE
. I think you should also look at PuTTY and PLink, and you should also see this here:
对于您的应用,我建议CSCRIPT.EXE
. 我认为你也应该看看 PuTTY 和 PLink,你也应该在这里看到: