简体   繁体   English

批量更改目录并使用当前目录作为命令

[英]Batch Change dir and use current dir as command

i try to write a CMD to run a script written by me. 我尝试编写CMD来运行我编写的脚本。

Script syntax is: 脚本语法为:

luajit.exe loader.lua nyufxlua "workingpath" suffix

workingpath and location of library are different. 库的工作路径和位置不同。

I tried following: 我尝试了以下操作:

@echo off

IF "%1%" == "" (
    GOTO :NOFILE
) ELSE (
    GOTO :FILE
)

:NOFILE
ECHO NO FILE GIVEN!
GOTO :EXIT

:FILE
SET "P=%CD%"
PUSHD C:\Projects\FXSpindle\trunk\deps\script\bin
luajit.exe loader.lua nyufxlua "%P%" %1%

:EXIT

I switch direcotry, run my file, but paramether "workingdir" is not correct. 我切换目录,运行文件,但参数“ workingdir”不正确。 workingdir should be the path i runned this scirpt from (script is stored in System32 of my Windows) workingdir应该是我运行此脚本的路径(脚本存储在Windows的System32中)

As "workingdir" is always C:\\Projects\\FXSpindle\\trunk\\deps\\script\\bin given, but not the path i have opened my command line... 由于“ workingdir”始终是C:\\ Projects \\ FXSpindle \\ trunk \\ deps \\ script \\ bin给定的,但不是我打开命令行的路径...

How to solve this problem? 如何解决这个问题呢?

i have the problem solved. 我解决了问题。 I havent realized that i have to use POPD after PUSHD - so i was in wrong directory... 我还没有意识到在PUSHD之后必须使用POPD-所以我的目录错误了...

The correct code is: 正确的代码是:

@echo off

IF "%1%" == "" (
    GOTO :NOFILE
) ELSE (
    GOTO :FILE
)

:NOFILE
ECHO NO FILE GIVEN!
GOTO :EXIT

:FILE
SET "P=%CD%"
POPD C:\Projects\FXSpindle\trunk\deps\script\bin
luajit.exe loader.lua nyufxlua "%P%" %1%

:EXIT

使用%1来访问第一个参数,而不能在结尾加上%

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

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