InstallScript无法从命令提示符下读取包含结果的文本文件 [英] InstallScript can not read text file containing result from command prompt

查看:128
本文介绍了InstallScript无法从命令提示符下读取包含结果的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写Installscript函数以在命令提示符下运行命令,将结果从控制台重定向到文本文件,然后读取文本文件以获取信息.

I am writing a Installscript function to run a command in command prompt, redirect the result from console to a text file, then read the text file for information.

// send command method
STRING szCmdPath, szCmdLine ;
szCmdPath = "C:\\WINDOWS\\system32\\cmd.exe";
szCmdLine = "/c wslconfig /l > D:\\output.txt";
LaunchAppAndWait(szCmdPath, szCmdLine, WAIT);

send命令方法未按我的要求使用szCmdLine运行命令,它无法识别该命令并产生以下错误:

the send command method did not run the command with szCmdLine as I desired, it failed to recognize the command and produce the following error:

'wslconfig'不被识别为内部或外部命令, 可操作的程序或批处理文件.

'wslconfig' is not recognized as an internal or external command, operable program or batch file.

但是,如果我手动启动cmd.exe而不是使用脚本,它将运行命令完全正常.我的脚本出了什么问题以及如何解决这些问题?谢谢大家.

However, if I start cmd.exe manually instead of using my script, it runs the command perfectly fine. What is wrong with my script and how to fix these problems? Thank you all in advance.

推荐答案

我在这里看到两个可能引起混淆的元素.一种是32位进程的文件系统重定向(导致加载无法找到wslconfig的32位cmd.exe).另一个问题是,输出重定向的命令行处理是否会满足您的要求.

I see two potentially confusing elements here. One is filesystem redirection of 32-bit processes (resulting in loading a 32-bit cmd.exe that cannot find wslconfig). The other is a question of whether command line processing of the output redirection will do what you want.

要进行测试,可以尝试以下操作:

To test, here are some things you could try:

  • 从显式32位命令提示符(c:\Windows\SysWow64\cmd.exe)运行测试
  • 运行其他命令,例如cmd /c echo got-it > D:\output.txt
  • Run a test from an explicitly 32-bit command prompt (c:\Windows\SysWow64\cmd.exe)
  • Run a different command, such as cmd /c echo got-it > D:\output.txt

我怀疑您可能必须同时解决这两个问题,但坚信32位上下文存在问题.要解决此上下文,请考虑使用

I suspect you may have to address both, but strongly believe the 32-bit context is problematic. To address the context, consider altering your code to the following, using WINSYSDIR64:

...
szCmdPath = WINSYSDIR64 ^ "cmd.exe";
...
Disable(WOW64FSREDIRECTION);
LaunchAppAndWait(...)
Enable(WOW64FSREDIRECTION);

(作为一种替代方法,您可以从32位上下文中使用C:\ Windows \ Sysnative来访问64位文件夹,而无需禁用WOW64FSREDIRECTION.不幸的是,该路径中没有填充变量,因此您必须构造或硬编码该路径.)

(As an alternate approach, you can use C:\Windows\Sysnative from a 32-bit context to access the 64-bit folder without disabling WOW64FSREDIRECTION. Unfortunately there isn't a variable populated with that path so you have to construct or hard code that path.)

要解决输出潜在的重定向问题,请考虑引用/c的参数:

To address the output potential redirection problem, consider quoting the arguments to /c:

...
szCmdLine = "/c \"wslconfig /l > D:\\output.txt\"";
...

这篇关于InstallScript无法从命令提示符下读取包含结果的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆