Search code examples
batch-filesetcd

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?


Solution

  • 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