批处理文件不接受参数在1%的形式,2% [英] Batch File Not Accepting Parameter in the form of %1, %2

查看:595
本文介绍了批处理文件不接受参数在1%的形式,2%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的脚本,做FTP上传,关键的一点是,我要传递的参数,如主机名,用户名,密码等输入到蝙蝠文件。

I have a simple script that does ftp uploading, the key thing is that I want to pass parameters such as host name, username, password etc into the bat file.

这是我的剧本

@ftp -i -s:"%~f0"&GOTO:EOF
open %1
%2
%3
!:--- FTP commands below here ---
lcd "%4"
cd  %5
binary
put "%6"
disconnect
bye

现在,当我调用脚本的命令行,并通过在%1 %2 .. 。在%1 %2 内容不会得到我的命令行参数替换。这是我的命令行:

Now, when I call the script from command line and pass in the %1, %2 ... the %1, %2 content won't get replaced by my command line parameters. This is my command line:

ftp.bat "first" "second" "third" "forth" "five" "six"

而不是%1 变得第一%2 变成第二等,在%1 仍然%1 ,所以基本上我开一个ftp侧名为%1 这是完全荒谬的。

Instead of %1 becomes first, %2 becomes second and so on, the %1 remains %1, so essentially I am opening a ftp side with the name %1 which is completely nonsensical.

什么我做错了?

推荐答案

这是因为,在您实际上是在处理文件来看,这不是一个批处理脚本都没有。

That's because, at the point where you're actually processing the file, it's not a batch script at all.

这是一个FTP脚本,它没有做任何花哨替代。

It's an FTP script, which does not do any of that fancy substitution.

您可以得到一个临时文件(基于原始文件,以避免冲突),你想要的效果这样的:

You can get your desired effect with a temporary file (based on the original file to avoid clashes) thus:

@setlocal enableextensions enabledelayedexpansion
@echo off
set tmpfl=%~f0.tmp
echo>"%tmpfl%" open %1
echo>>"%tmpfl%" %2
echo>>"%tmpfl%" %3
echo>>"%tmpfl%" lcd "%4"
echo>>"%tmpfl%" cd %5
echo>>"%tmpfl%" binary
echo>>"%tmpfl%" put "%6"
echo>>"%tmpfl%" disconnect
echo>>"%tmpfl%" bye
type "%tmpfl%" && rem ftp -i -s:"%tmpfl%"
del /q "%tmpfl%"
endlocal

键入行是在那里进行调试。当你满意的剧本,改:

The type line is in there for debugging. When you're happy with the script, change:

type "%tmpfl%" && rem ftp -i -s:"%tmpfl%"

ftp -i -s:"%tmpfl%"

这篇关于批处理文件不接受参数在1%的形式,2%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆