2013-05-28 91 views
0

以下是我正在嘗試執行的操作,以便在遠程服務器上運行cmd。在serverList.txt帶有空格的批處理文件傳遞路徑

一個例子:

服務器名& E:\ A \ B \ C \ ABC EDF \ ABC \

@echo on 
cd /d %~dp0 
setlocal EnableDelayedExpansion 
set serverList=serverList.txt 
for /f "usebackq tokens=1,2* delims=&" %%A in ("%serverList%") DO ( 
    SET directory = %%B 
    wmic /node:%%A process call create "cmd /c cd /d !directory! & !directory!\hello.cmd" 
) 
endlocal 
Pause 

但你可以看到,該目錄的路徑有一個白色的空間,我嘗試了雙引號,但沒有幫助。它沒有做任何事情,沒有它完美的工作空間。

想知道我出錯的地方。非常感激!

JS

+0

是你使用的確切批處理文件嗎?應該使用'!directory!'而不是'%directory%'來使'EnableDelayedExpansion'正常工作。我不知道在目錄名稱中如何使用或不使用空格。 –

+0

耶!試過!目錄!但沒有運氣。它就像「cmd/c cd/d %% B&%% B \ hello.cmd」,並且完美運行直到我發現一些目錄之間有空格。 – user2381130

回答

1

試試這個:

 
@echo on 
cd /d %~dp0 
setlocal EnableDelayedExpansion 
set "serverList=serverList.txt" 
for /f "usebackq tokens=1,2* delims=&" %%A in ("%serverList%") DO ( 
    SET "directory=%%B" 
    wmic /node:%%A process call create "cmd /c cd /d "!directory!" & "!directory!\hello.cmd"" 
) 
endlocal 
Pause 
+0

只是試過,並沒有工作。認爲報價應該在不同的地方結束? – user2381130

+0

錯誤是無效的動詞開關 – user2381130

+0

我通過robocopy「!目錄!」做了一個robocopy。實際上它確實採用了空間的整個路徑。所以想知道那個世界可能有什麼問題。 :( – user2381130

0

你不需要延遲擴展,你可以使用%%乙

如果失敗的地方WMIC之前的ECHO,看看是什麼它打印到控制檯。

@echo on 
cd /d %~dp0 
set "serverList=serverList.txt" 
for /f "usebackq tokens=1,2* delims=&" %%A in ("%serverList%") DO ( 
    wmic /node:%%A process call create "cmd /c cd /d "%%B" & hello.cmd " 
) 
endlocal 
Pause 

或者對於踢腿,試試這個。 Wmic是使用forIndo命令的奇怪工具。

@echo on 
cd /d %~dp0 
set "serverList=serverList.txt" 
for /f "usebackq tokens=1,2* delims=&" %%A in ("%serverList%") DO call :next "%%A" "%%B" 
pause 
goto :eof 
:next 
wmic /node:%~1 process call create "cmd /c cd /d "%~2" & hello.cmd " 
goto :EOF 
+0

嘗試過,但在我的結尾沒有運氣:(思考wmic有一個不同的結構比我想象的。 – user2381130

相關問題