Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 通过WMIC的批处理脚本输出不一致_Windows_Batch File_Cmd_Wmic - Fatal编程技术网

Windows 通过WMIC的批处理脚本输出不一致

Windows 通过WMIC的批处理脚本输出不一致,windows,batch-file,cmd,wmic,Windows,Batch File,Cmd,Wmic,我正在尝试使用WMIC从远程服务器执行批处理脚本,并获得附加的输出为“WMIC_output.JPG” 我从命令中看到的输出不准确。当我在实际服务器上运行相同的脚本时,我可以看到正确的输出。请参阅随附的屏幕截图“Output.JPG” 现在我假设远程执行的脚本为我提供了进程ID和脚本退出状态 请告知WMIC参数/开关,以获得所需输出 -Abhi通过为cmd.exe指定/k选项来执行它。您还需要使用引号保护批处理文件名称中的空格 C:\Users\user>wmic /node:loca

我正在尝试使用WMIC从远程服务器执行批处理脚本,并获得附加的输出为“WMIC_output.JPG”

我从命令中看到的输出不准确。当我在实际服务器上运行相同的脚本时,我可以看到正确的输出。请参阅随附的屏幕截图“Output.JPG”

现在我假设远程执行的脚本为我提供了进程ID和脚本退出状态

请告知WMIC参数/开关,以获得所需输出


-Abhi

通过为
cmd.exe
指定
/k
选项来执行它。您还需要使用引号保护批处理文件名称中的空格

C:\Users\user>wmic /node:localhost process call create 'cmd.exe  /k "C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat" '
详细信息:

当你执行

C:\Users\user>wmic /node:localhost process call create "cmd.exe  C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat"
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ProcessId = 2192;
        ReturnValue = 0;
};
cmd.exe
需要
/k
选项。当我们添加“/k”选项时

C:\Users\user>wmic /node:localhost process call create "cmd.exe  /k C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat"
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ProcessId = 4064;
        ReturnValue = 0;
};
并在弹出的窗口中显示:

'C:\\Users\user\\AWS__APIGATEWAY' is not recognized as an internal or external command,
operable program or batch file.

C:\Windows\system32>
当我们在批处理文件名周围加上引号时,它将正确执行并在新的cmd窗口中生成输出:

C:\Users\user>wmic /node:localhost process call create 'cmd.exe  /k "C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat" '
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ProcessId = 5788;
        ReturnValue = 0;
};

通过为
cmd.exe
指定
/k
选项来执行它。您还需要使用引号保护批处理文件名称中的空格

C:\Users\user>wmic /node:localhost process call create 'cmd.exe  /k "C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat" '
详细信息:

当你执行

C:\Users\user>wmic /node:localhost process call create "cmd.exe  C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat"
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ProcessId = 2192;
        ReturnValue = 0;
};
cmd.exe
需要
/k
选项。当我们添加“/k”选项时

C:\Users\user>wmic /node:localhost process call create "cmd.exe  /k C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat"
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ProcessId = 4064;
        ReturnValue = 0;
};
并在弹出的窗口中显示:

'C:\\Users\user\\AWS__APIGATEWAY' is not recognized as an internal or external command,
operable program or batch file.

C:\Windows\system32>
当我们在批处理文件名周围加上引号时,它将正确执行并在新的cmd窗口中生成输出:

C:\Users\user>wmic /node:localhost process call create 'cmd.exe  /k "C:\\Users\user\\AWS__APIGATEWAY - 4xerror - Windows.bat" '
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ProcessId = 5788;
        ReturnValue = 0;
};

正如Npcmaka告诉您的,将输出发送到一个文件,然后读取它。使用
wmic
很难转义。请试一试

set "fileout=c:\....\output.txt"
wmic /node:dnvprdsis11.....org process call create "cmd /c E:\\sitescope\\...Windows.bat > \"%fileout%\"" >NUL 2>NUL 
ping localhost -n 2 -w 300 >NUL
if exist "%fileout%" type "%fileout%"

…>\“%fileout%\…”
可能还需要转义
…^>\%fileout%\”..

正如Npcmaka告诉您的那样,将输出发送到一个文件,然后读取它。使用
wmic
很难转义。请试一试

set "fileout=c:\....\output.txt"
wmic /node:dnvprdsis11.....org process call create "cmd /c E:\\sitescope\\...Windows.bat > \"%fileout%\"" >NUL 2>NUL 
ping localhost -n 2 -w 300 >NUL
if exist "%fileout%" type "%fileout%"

…>\“%fileout%\…”
可能还需要转义
…^>\%fileout%\”..

是否可以将输出重定向到文件,然后读取?在批处理文件中放入“cd”命令。它可能会显示您在某些目录中,如“C:\Windows\System32”或类似的默认目录。您可能必须修改bat文件,使其在开始执行之前到达正确的目录。@blackpen在执行命令cd C:\Program Files\Amazon\AWSCLI\C:aws命令之前,我正在更改脚本中的目录-Abhi@npocmaka我确实按照建议将输出重定向到文件..aws命令..>>E:\SiteScope\logs\AWSOutput.txt,但未创建该文件。因此,这意味着脚本不是通过wmic远程执行的。在实际服务器上运行脚本时,可以看到输出文件中的内容。关于如何使wmic运行脚本的任何进一步建议/输入?-Abhi@AbhinandanAithal,尝试使用单个命令运行批处理文件
echo ok
,并将其重定向到文件。如果这不起作用,那么您在创建文件(写入)的权限方面存在问题,或者在执行批处理文件的权限方面存在问题。在此处发布命令和结果。是否可以将输出重定向到文件,然后读取?在批处理文件中放入“cd”命令。它可能会显示您在某些目录中,如“C:\Windows\System32”或类似的默认目录。您可能必须修改bat文件,使其在开始执行之前到达正确的目录。@blackpen在执行命令cd C:\Program Files\Amazon\AWSCLI\C:aws命令之前,我正在更改脚本中的目录-Abhi@npocmaka我确实按照建议将输出重定向到文件..aws命令..>>E:\SiteScope\logs\AWSOutput.txt,但未创建该文件。因此,这意味着脚本不是通过wmic远程执行的。在实际服务器上运行脚本时,可以看到输出文件中的内容。关于如何使wmic运行脚本的任何进一步建议/输入?-Abhi@AbhinandanAithal,尝试使用单个命令运行批处理文件
echo ok
,并将其重定向到文件。如果这不起作用,那么您在创建文件(写入)的权限方面存在问题,或者在执行批处理文件的权限方面存在问题。在这里发布命令和结果。我仍然得到相同的错误。我不知道我会错在哪里。C:\Users\a-Abhinandan.aithal>wmic/node:processcall create'cmd.exe/k“E:\\SiteScope\\scripts.remote\\AWS\u APIGATEWAY-4xxerror-Win dows.bat”'正在执行(Win32_进程)->create()方法执行成功。Out参数:uu参数{ProcessId=5128;ReturnValue=0;}的实例-abhi如果您用一行测试命令替换网关脚本的内容,是否成功?我仍然收到相同的错误。我不知道我会错在哪里。C:\Users\a-Abhinandan.aithal>wmic/node:processcall create'cmd.exe/k“E:\\SiteScope\\scripts.remote\\AWS\u APIGATEWAY-4xxerror-Win dows.bat”'正在执行(Win32_进程)->create()方法执行成功。Out参数:uu参数{ProcessId=5128;ReturnValue=0;}的实例-abhi如果用一行测试命令替换网关脚本的内容,是否成功?