php exec vbs 脚本只能在循环中第一次运行
php exec vbs script works only first time in a loop
我正在编写脚本以将 excel 文件转换为 csv 文件。 Excel 个文件位于下载文件夹中,并以 "START" 开头。只有第一个文件被转换,然后 php 仍然是 运行,但没有任何反应。 运行 从浏览器中我可以看到圆圈永远是 运行,就像加载网站一样。这是代码:
$path = "C:\Users\tom\Downloads\";
foreach(glob($path."*.xls") as $excel_file) {
$substr = substr($excel_file, 24, 5);
if($substr = "START") {
$csv_file = str_replace(".xls", ".csv", $excel_file);
exec("$path"."csv.vbs $excel_file $csv_file");
}
}
我使用的脚本是csv.vbs
脚本,代码是:
if WScript.Arguments.Count < 2 Then
WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsToCsv SourcePath.xls Destination.csv"
Wscript.Quit
End If
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
oBook.SaveAs WScript.Arguments.Item(1), 6
oBook.Close False
oExcel.Quit
WScript.Echo "Done"
使用shell_exec
是一样的。这里有什么问题?
$substr 不等于 "START" 根据 php.net
substr ( string $string , int $start [, int $length ] )
START 是 5 个字符,所以
$substr = substr($excel_file, 0, 5);
还有一个错误的比较try
if($substr = "START")
正确的比较是使用==或===进行严格比较
if($substr == "START")
删除了 csv.vbs
中的最后一行
WScript.Echo "Done"
并且工作正常
我正在编写脚本以将 excel 文件转换为 csv 文件。 Excel 个文件位于下载文件夹中,并以 "START" 开头。只有第一个文件被转换,然后 php 仍然是 运行,但没有任何反应。 运行 从浏览器中我可以看到圆圈永远是 运行,就像加载网站一样。这是代码:
$path = "C:\Users\tom\Downloads\";
foreach(glob($path."*.xls") as $excel_file) {
$substr = substr($excel_file, 24, 5);
if($substr = "START") {
$csv_file = str_replace(".xls", ".csv", $excel_file);
exec("$path"."csv.vbs $excel_file $csv_file");
}
}
我使用的脚本是csv.vbs
脚本,代码是:
if WScript.Arguments.Count < 2 Then
WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsToCsv SourcePath.xls Destination.csv"
Wscript.Quit
End If
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
oBook.SaveAs WScript.Arguments.Item(1), 6
oBook.Close False
oExcel.Quit
WScript.Echo "Done"
使用shell_exec
是一样的。这里有什么问题?
$substr 不等于 "START" 根据 php.net
substr ( string $string , int $start [, int $length ] )
START 是 5 个字符,所以
$substr = substr($excel_file, 0, 5);
还有一个错误的比较try
if($substr = "START")
正确的比较是使用==或===进行严格比较
if($substr == "START")
删除了 csv.vbs
WScript.Echo "Done"
并且工作正常