java “cscript //NoLogo”代表什么?

xvw2m8pv  于 2022-12-02  发布在  Java
关注(0)|答案(2)|浏览(69)

这是一个java程序代码,它运行记事本程序并粘贴存储在该程序本身中的特定文本......
我想知道你是否能解释一下String vbs的值,还有File file,以及Process p中的("cscript //NoLogo " + file.getPath())。如果你同样慷慨,那么请解释一下整个代码。
我是一个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();
   }
 }
fcg9iug3

fcg9iug31#

虽然这个问题 * 不是 * 主要关于cscript //NoLogo,不管它的标题,它仍然很好地谷歌为这个短语,所以让我们回答太多的细节了。
我不知道为什么他们称之为"logo",但它正是你从内置的help@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>

因此,如果你正在管道输出,而不希望所有的微软样板,//Nologo-ify它。

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中包含var spam = "spam";。)
而且,哇,这是一个可怕的错综复杂的方式来获得文本到记事本。我猜它更多的是教如何写一个文件和exec一个命令从Java,也许?

kgsdhlau

kgsdhlau2#

你基本上要做的是:
1.创建包含脚本的字符串(String vbs = ...
1.将其写入文件(File file = File...fw.close()
1.通过调用cscript(Process p = Runtime.getRuntime().exec(...))在单独的进程中执行此脚本
关于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

相关问题