编程语言
首页 > 编程语言> > java-“ cscript // NoLogo”代表什么?

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

作者:互联网

这是一个运行记事本程序并粘贴存储在此程序本身中的特定文本的Java程序代码.

我想知道是否可以向我解释String vbs值,以及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();
   }
 }

解决方法:

您基本上要做的是:

>创建一个包含脚本的字符串(字符串vbs = …)
>将其写入文件(文件文件= File …至fw.close())
>通过调用cscript在单独的进程中执行此脚本(进程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

标签:file,jtextfield,filewriter,notepad-2,java
来源: https://codeday.me/bug/20191101/1980309.html