Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.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
Php 在命令行上传递多部分变量_Php_Command Line - Fatal编程技术网

Php 在命令行上传递多部分变量

Php 在命令行上传递多部分变量,php,command-line,Php,Command Line,我有一个从命令行运行的php文件。该脚本有一个必需的未命名元素(file.xml),但允许某些选项(例如--conf LocalSettings.php) 我的问题是我的一个选项需要通过一个设置(设置1)。这适用于大多数脚本,例如: php runJobs.php --conf LocalSettings.php setting1 但不是具有必需的未命名元素的,例如: php importDump.php --conf LocalSettings.php setting1 file.xml

我有一个从命令行运行的php文件。该脚本有一个必需的未命名元素(file.xml),但允许某些选项(例如--conf LocalSettings.php)

我的问题是我的一个选项需要通过一个设置(设置1)。这适用于大多数脚本,例如:

php runJobs.php --conf LocalSettings.php setting1
但不是具有必需的未命名元素的,例如:

php importDump.php --conf LocalSettings.php setting1 file.xml
我试着把部分放在引号里,所以它会被当作一块代码来处理,但它不起作用

php importDump.php --conf "LocalSettings.php setting1" file.xml
我只能修改LocalSettings.php脚本以及如何在命令行上调用

我如何让这个命令在需要未命名部分的命令(importDump.php)和不需要未命名部分的命令(runJobs.php)上工作


作为参考,我使用
$argv[3]

获取LocalSettings.php脚本中的设置输入,不知道为什么加引号对您不起作用

$ php arg_test.php --conf "test foo" file.xml
array(4) {
  [0]=>
  string(12) "arg_test.php"
  [1]=>
  string(6) "--conf"
  [2]=>
  string(8) "test foo"
  [3]=>
  string(8) "file.xml"
}
arg_test.php只是执行

$ php arg_test.php --conf "test foo" file.xml
array(4) {
  [0]=>
  string(12) "arg_test.php"
  [1]=>
  string(6) "--conf"
  [2]=>
  string(8) "test foo"
  [3]=>
  string(8) "file.xml"
}