简体   繁体   中英

Batch Change dir and use current dir as command

i try to write a CMD to run a script written by me.

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 should be the path i runned this scirpt from (script is stored in System32 of my Windows)

As "workingdir" is always C:\\Projects\\FXSpindle\\trunk\\deps\\script\\bin given, but not the path i have opened my command line...

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...

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来访问第一个参数,而不能在结尾加上%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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