简体   繁体   English

带有参数的PHP Windows Bat文件

[英]PHP Windows Bat file with arguments

We currently have to import around 200 students into our active directory. 我们目前必须将大约200名学生导入我们的活动目录。 We have a BAT file which creates the users and folders on the servers. 我们有一个BAT文件,用于在服务器上创建用户和文件夹。

I've written a script which scans our MSSQL database for the new students, saves them into an array, and then uses system() to call cmd.exe and run the BAT file to create the students. 我编写了一个脚本,它扫描我们的MSSQL数据库中的新学生,将它们保存到一个数组中,然后使用system()调用cmd.exe并运行BAT文件来创建学生。

The BAT file is located on my Y drive (which is on another server). BAT文件位于我的Y驱动器(位于另一台服务器上)。 We currently also use DFS paths so I can access the bat file that way as well. 我们目前还使用DFS路径,因此我也可以通过这种方式访问​​bat文件。

Its worth noting: 1) Both paths to the BAT file have spaces in them 2) I need to pass arguments to the BAT file as well 值得注意的是:1)BAT文件的两条路径都有空格2)我还需要将参数传递给BAT文件

At the moment, This is the state of my system() argument in PHP: 目前,这是我在PHP中的system()参数的状态:

$bat = escapeshellcmd("cmd /c Y:\SharedRes\Path To Createstudent\createstudent.bat {$stuArray['forename']} {$stuArray['surname']} {$stuArray['username']} {$stuArray['year']} {$stuArray['sf']}");
system($bat);

And with the DFS Path: 并使用DFS路径:

$bat = escapeshellcmd("cmd /c '\\organisation.local\Path To Createstudent\createstudent.bat {$stuArray['forename']} {$stuArray['surname']} {$stuArray['username']} {$stuArray['year']} {$stuArray['sf']}'");
system($bat);

Each time I try to run this, I get the following error: 每次我尝试运行它,我收到以下错误:

The filename, directory name, or volume label syntax is incorrect

Any ideas how to get PHP to actually run the BAT file? 有任何想法如何让PHP实际运行BAT文件? I'm currently stumped. 我现在很难过。

Many thanks 非常感谢

Phil 菲尔

PS I am running the PHP script via command line: PS我通过命令行运行PHP脚本:

php.exe -f "C:\import.php"

if the batch file is in a path with spaces you need to quote the argument: 如果批处理文件位于带空格的路径中,则需要引用该参数:

cmd /c "Y:\SharedRes\Path To Createstudent\createstudent.cmd" ...

Also if the parameters contain spaces you need to quote them too. 此外,如果参数包含空格,您也需要引用它们。 Single quotes are not recognised by cmd , it has to be double quotes. cmd无法识别单引号,它必须是双引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM