windows - Syntax error in a batch script when asking for user input (/P) -


i've asked couple of people issue is, , have walked away twice without solution. haven't played batch before, may simple mistake. code supposed give list of processes using wmic. eventually, i'd set kill processes (which should able easily), have on roadblock first.

@echo off set getprocesslistlocal=wmic process name,processid set /p remotemachinecheck=type name of remote machine view processes of (or type local local machine), , press enter. if %remotemachinecheck%==local ( %getprocesslistlocal% ) else ( set remotemachine=%remotemachinecheck% set /p remoteuser=type user name access %remotemachine% with, press enter. set /p remotepassword=[type password %remoteuser% on %remotemachine%, press enter. watch back, won't hidden! set getprocesslistremote=wmic /node %remotemachine% /user:%remoteuser% /password:%remotepass% process name,processid %getprocesslistremote% ) echo end of list. press key choose process kill. @echo off pause>null 

first thing comment out @echo off (or change @echo on) can see line causing error.


second thing should @ fact commands processed substitutions before they're executed, not lines.

that means entire if ( ) else ( ) structure have substitution done on before remotemachine variable set, meaning won't set want, when want use it.

for example, code:

@echo off set xyzzy=plugh if a==a (     set xyzzy=twisty     echo %xyzzy% ) 

will not output twisty may think, instead gives plugh.

you need delayed expansion , !! expansion operator:

@setlocal enableextensions enabledelayedexpansion @echo off set xyzzy=plugh if a==a (     set xyzzy=twisty     echo !xyzzy! ) endlocal 

third thing, , suspect what's causing immediate problem, move ( end of if line:

if %remotemachinecheck%==local ( 

with ( on following line, generates error like:

the syntax of command incorrect. 

but here's tricky thing: outputs before if line, may lead believe error on previous line, per following transcript (indenting lines generated computer):

c:\pax> type qq1.cmd     set q=w     if a==a     (         echo yes     )  c:\pax> qq1      c>\pax> set q=w     syntax of command incorrect.      c:\pax> if a==a  c:\pax> type qq2.cmd     set q=w     if a==a (         echo yes     )  c:\pax> qq2      c>\pax> set q=w      c:\pax> if a==a (echo equal )     equal 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -