php - 如何从 php 触发批处理文件以及如何从 url 获取查询字符串并将其作为参数传递给批处理文件?
问题描述
这是我的批处理文件脚本我正在通过任务计划程序运行此脚本通过使用以下脚本,我可以将所有文件从 invoice_feed 文件夹复制到网络共享测试文件夹(shared_folder),两台服务器都通过 VPN 连接
Echo off
net use \\windows_servername\test_folder shared_folder_password /user:shared_folder_username
xcopy C:\Apache\htdocs\Invoices\invoice_feed \\windows_servername\\test_folder
如果我想将特定文件复制到网络共享文件夹,那么我将手动将该文件添加到上述批处理脚本中,它运行良好。下面是代码
Echo off
net use \\windows_servername\test_folder shared_folder_password /user:shared_folder_username
xcopy C:\Apache\htdocs\Invoices\invoice_feed\file_to_copy.csv \\windows_servername\\test_folder
我可以使用 PHP 运行这个脚本吗?如果是,那么我可以从 URL 传递动态值并传递它来代替特定的文件名,如下所示?
xcopy C:\Apache\htdocs\Invoices\invoice_feed\<?php echo $_GET['csv_file_name']?> \\windows_servername\\test_folder
或者有没有其他方法而不是在批处理文件中执行此操作,我的意思是完全使用 php?我正在尝试运行如下脚本
$file_name = $_GET['csv_file_name'];
echo exec('net use \\windows_servername\test_folder shared_folder_password /user:shared_folder_username');
echo exec('xcopy C:\Apache\htdocs\Invoices\invoice_feed\$file_name \\windows_servername\\test_folder');
但没有运气。它显示 0 个文件已复制。我在哪里做错了?
解决方案
推荐阅读
- javascript - 隐藏实现 CSS 按钮
- mysql - MySQL中的“停用词”一词是什么意思?
- c# - 我无法关闭此表单
- sql - 带有 SELECT 语句的尾随“000000000000003”
- asp.net-mvc - ASP.Net MVC 到 ASFS 调用抛出远程证书错误
- regex - Powershell JSON transformation removing unicode escape chars without removing literal \n
- flutter - 如何在颤动中预取 PageView 页面?
- sql-server - How to rename this column using AS for display
- swift - 元组在比较时造成破坏
- apache-spark - What is the difference between CAST(... to STRING) and BASE64(...)