在PHP上存储来自CLI命令输出(Windows)的值

在PHP上存储来自CLI命令输出(Windows)的值,php,variables,command-line-interface,Php,Variables,Command Line Interface,我试图从密码vault CLI输出中获取一个值(12345678),并将其存储在PHP中的变量中 例如,在PERL上,我使用的是: my $pass= qx("C:\\Program Files (x86)\\CyberArk\\ApplicationPasswordSdk\\CLIPasswordSDK.exe" GetPassword /p AppDescs.AppID=SOMEAPP /p Query="Safe=SAFE;Folder=Root;Object=DATABASEX" /o

我试图从密码vault CLI输出中获取一个值(
12345678
),并将其存储在PHP中的变量中

例如,在PERL上,我使用的是:

my $pass= qx("C:\\Program Files (x86)\\CyberArk\\ApplicationPasswordSdk\\CLIPasswordSDK.exe" GetPassword /p AppDescs.AppID=SOMEAPP /p Query="Safe=SAFE;Folder=Root;Object=DATABASEX" /o Password);

chomp($pass);

变量
$pass
的值是
12345678
,但我无法在PHP上复制它,任何人都可以帮助我吗?

在PHP中,您可以使用exec()方法执行并获得命令行执行的输出

$execResponse = exec('whoami', $output, $return_var);
echo $execResponse; // This will print the output from command line
print_r($output); // This will have the same output in an array.
$command:此参数用于保存将执行的命令

$output:此参数用于指定将由命令的每一行输出填充的数组


$return\u var:$return\u var参数与输出参数一起出现,然后返回将写入此变量的已执行命令的状态。

您会遇到什么错误?