wmic / node:服务器进程调用create不工作?

问题描述 投票:0回答:1

我试图让服务器运行python脚本,然后将脚本的输出保存到我​​调用命令的计算机。这是命令:

wmic /node:server1 process call create "cmd.exe /c C:\python.exe C:\python\hello.py >> Z:\test\result.txt"

我在http://blog.commandlinekungfu.com/2009/05/episode-31-remote-command-execution.html上读过这篇文章,但它是2009年的一篇旧文章。

server1是我希望运行python脚本的服务器的服务器名称。在该服务器上,Z驱动器映射到我从中调用命令的计算机的C驱动器。 C:\ python.exe和C:\ python \ hello.py是服务器的C盘。我尝试过使用UNC路径但是也没用。

所有hello.py都打印出“Hello”标准输出。

我已经通过在服务器中打开命令提示符然后运行它来验证命令cmd.exe /c C:\python.exe C:\python\hello.py >> Z:\test\result.txt的工作原理。它创建一个名为result.txt的文件,其中包含“Hello”

但是,使用wmic / node:server1进程调用create不会创建文件result.txt。

我也试过了

wmic /node:server1 /user:"adminUsername" /password:"adminUsersPw" process call create "cmd.exe /c C:\python.exe C:\python\hello.py >> Z:\test\result.txt"

没有运气。

当我运行该命令时,我得到类似的东西:

Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
    ProcessId = 4116;
    ReturnValue = 0;
};

这对我来说很奇怪,因为它似乎没有运行命令。有任何想法吗?

cmd wmic
1个回答
0
投票

使用WMIC,您必须对命令进行双重包装,以便将重定向器(>)转换为内部命令(whoami)而不是outter命令(cmd)。这是一个例子,包括我刚用过的系统的输出:

Cmd.exe:

$> dir \\NameOfRemoteSystem\c$\temp\z.txt
File Not Found


$> wmic /node:NameOfRemoteSystem process call create 'cmd.exe /c "whoami /all >c:\temp\z.txt"'
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ProcessId = 20460;
        ReturnValue = 0;
};


$> dir \\NameOfRemoteSystem\c$\temp\z.txt
03/27/2019  04:40 PM            17,977 z.txt
© www.soinside.com 2019 - 2024. All rights reserved.