簡體   English   中英

將變量傳遞到批處理文件中

[英]Pass variable into Batch file

我有一個工作正常的腳本,要求我將變量傳遞給批處理文件test.bat

腳本

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

批處理文件

@echo off

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

它不起作用。 如果我使用userIP調用腳本,它將返回空白輸出。

但是,如果我不使用批處理文件並替換

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

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

那就完美了。 如果我使用userIP調用,它將返回當前用戶。

如何解決這個問題?

由於這是Windows批處理文件,而不是POSIX.2兼容的外殼,

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

應該

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

(順便說一句,如果它 POSIX兼容的外殼,則需要在-x "$1"引用,以確保正確傳遞參數)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM