vbscript - vb脚本提取可执行jar文件响应
问题描述
我有一个场景来执行一个可执行的 jar 文件,然后需要从命令提示符捕获响应。
Option Explicit
Dim StrCmd,Path,processFile,str
Path = "D:\modulefolder"
processFile = "java -jar xxx.jar"
StrCmd = "CD /D "& Path & " & " & processFile &""
Call Run(StrCmd,1,False)
Function Run(StrCmd,Console,bWaitOnReturn)
Dim ws,MyCmd,Result, str1
Set ws = CreateObject("wscript.Shell")
'A value of 0 to hide the MS-DOS console
If Console = 0 Then
MyCmd = "CMD /K " & StrCmd & ""
Result = ws.run(MyCmd,Console,bWaitOnReturn)
*some code using sendkeys to type in command prompt****
有人可以告诉我最后我应该如何从命令提示符中提取响应代码..
例如,我得到响应代码 201 表示通过,400 或 405 表示失败场景。
解决方案
stdout
将和的输出重定向stderr
到一个文本文件并阅读:
java -jar myApp.jar >file.txt 2>&1
这会将 jar 文件的输出重定向到file.txt
,您可以使用FileSystemObject
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim File : Set File = Fso.OpenTextFile("Path/to/file.txt", 1)
Dim Text : Text = File.ReadAll
Text
现在包含文件的内容作为变量供您根据需要使用。
推荐阅读
- chatbot - Microsoft Teams:聊天消息中的内嵌图像链接 - 它们可以在其他聊天中重复使用吗?
- amazon-web-services - 从 aws 中的 s3 存储桶中恢复替换的图像
- frontend - 是否可以从 wolframscript 停止/杀死 Mathematica Frontend?
- javascript - 如何将 React 组件附加到 html 元素 i?
- laravel - 用户在 Laravel 中注册时发送电子邮件
- android - Delphi 10.3.3 , Android App AutoStart on Boot ( Android 8.x , 10.x )
- c# - 肥皂请求的授权
- excel - 如何将定义的范围复制到 Excel for Mac 中的公式中?
- c++ - c++ 11 中的 if else 编译时间
- c# - 什么是 C# 对象模式匹配?