Glowie
Glowie

Reputation: 2309

Pass variable into Batch file

I have a script that works that requires me to pass variable to batch file, test.bat

script

pst = subprocess.Popen(
        ["test.bat",  userIP],
        stdout = subprocess.PIPE,
        stderr = subprocess.PIPE
    )

batch file

@echo off

D:\pstools\psloggedon.exe -l -x $1

It is not working. If I invoke the script with userIP it return blank output.

But if I do not use batch file and replace

pst = subprocess.Popen(
        ["test.bat",  userIP],
        stdout = subprocess.PIPE,
        stderr = subprocess.PIPE
    )

with

pst = subprocess.Popen(
        ["D:\pstools\psloggedon.exe", "-l", "-x",  userIP],
        stdout = subprocess.PIPE,
        stderr = subprocess.PIPE
    )

then it works perfectly. If I invoke with userIP it returns the current user.

How to fix this?

Upvotes: 0

Views: 636

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295500

Since this is a Windows batch file, not a POSIX.2-compatible shell,

D:\pstools\psloggedon.exe -l -x $1

should be

D:\pstools\psloggedon.exe -l -x %1

(By the way, if it were a POSIX-compatible shell, you'd need to quote, as in -x "$1", to ensure that your parameter were passed through correctly).

Upvotes: 1

Related Questions