gpt4 book ai didi

php - 如何将php变量传递给windows批处理文件

转载 作者:可可西里 更新时间:2023-11-01 09:58:48 29 4
gpt4 key购买 nike

我想通过 php 执行我的批处理文件,并将一些值从 php 传递到批处理文件。批处理文件的目的是将 csvs 文件导出到 ftp。通过命令行它可以完美地工作,但不能与 php 一起使用。下面给出的是我的批处理和 php 文件

测试.bat

@echo off
set ftp_domain=%1
echo FTP Domain to Connect to %ftp_domain%
set ftp_username=%2
echo FTP User Name %ftp_username%
set ftp_password=%3
echo FTP Password %ftp_password%
set data_folder=%4
echo Folder to upload Files from %data_folder%
del ftpscript.txt
echo open %ftp_domain%>>ftpscript.txt
echo %ftp_username%>>ftpscript.txt
echo %ftp_password%>>ftpscript.txt
echo !:--- LOGGED INTO FTP --- >>ftpscript.txt
echo pwd >>ftpscript.txt
echo !:--- CHANGE DIRECTORY TO MAGENTO-CONNECTOR FOLDER --->>ftpscript.txt
echo cd Magento-Connector>>ftpscript.txt
echo !:--- CHANGE DIRECTORY TO DATA FOLDER --->>ftpscript.txt
echo cd data>>ftpscript.txt
echo !:--- SET LOCAL DATA DIRECTORY FOR FILE UPLOAD --->>ftpscript.txt
echo lcd %data_folder%>>ftpscript.txt
echo !:--- SET FILE TRANSFER MODE TO BINARY --->>ftpscript.txt
echo binary>>ftpscript.txt
echo !:--- RECURSIVELY UPLOAD FILES --->>ftpscript.txt
echo mput "*.csv">>ftpscript.txt
echo !:--- LIST OF FILES UPLOADED INTO FTP --->>ftpscript.txt
echo dir>>ftpscript.txt
echo !:--- DISCONNECT --->>ftpscript.txt
echo disconnect>>ftpscript.txt
echo !:--- EXIT FTP --->>ftpscript.txt
echo bye>>ftpscript.txt
echo Start Login to FTP Server
ftp -i -s:ftpscript.txt
echo Delete FTP SCRIPT FILE
del ftpscript.txt
echo End of Operation....exiting....

php文件

<?php
$var1 = "domain.com"; //this is domain
$var2 = "username"; //this is username
$var3 = "password"; //this is username
$var4 = "C:\myCSV_FolderPath";
$bat_file = "test.bat".escapeshellarg($var1)." ".escapeshellarg($var2)." ".escapeshellarg($var3)." ".escapeshellarg($var4);
$output = null;
exec($bat_file, $output);
?>

当我运行我的 php 文件时,它不会给出任何结果,我的 csv 文件也不会传输到 ftp。

最佳答案

我认为您只是在第一个变量之前缺少一个空格:

$bat_file = "test.bat ".escapeshellarg($var1)." ".escapeshellarg($var2)." ".escapeshellarg($var3)." ".escapeshellarg($var4);

关于php - 如何将php变量传递给windows批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28981117/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com