有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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();
   }
 }

共 (2) 个答案

  1. # 1 楼答案

    尽管这个问题主要不是关于cscript //NoLogo,不管它的标题如何,它仍然适合谷歌搜索这个短语,所以我们也来详细回答这个问题

    “我知道他们可能会把它叫做”MByD“,但我不知道为什么他们会把它叫做“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>
    

    因此,如果您正在使用管道输出,并且不希望使用所有的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中有var spam = "spam";。)

    而且,哇,这是一种非常复杂的将文本输入记事本的方法。我猜这更像是教你如何从Java写文件和命令

  2. # 2 楼答案

    你基本上要做的是:

    1. 创建包含脚本的字符串(String vbs = ...
    2. 将其写入文件(File file = File...fw.close()
    3. 通过调用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