2

I have to execute a command on a cluster to kill a group of processes.

start /wait winrs -r:NODENAME -u:USERNAME  -p:PASSWORD taskkill /FI \"USERNAME eq USER" /f

I can't redirect the output. I find on this site similar problems but the solution here:

Is there any way to redirect stderr output from a command run with "start" in the Windows command line?

doesn't work. I redirect winrs command but I need the redirection of taskkill. Any idea? Thanks.

Community
  • 1
  • 1

1 Answers1

0

This is totally untested, and I know nothing about winrs. But I believe it is only a matter of escaping the redirection the proper number of times. Assuming n is the number of escapes, then the number of carets required is 2 to the nth power, minus 1 ((2^n)-1).

If you want the output to be redirected to a file on the remote machine, then the redirection must be delayed until WINRS launches the remote process, so twice, once for START, and once for WINRS

start /wait winrs -r:NODENAME -u:USERNAME  -p:PASSWORD taskkill /FI \"USERNAME eq USER" /f ^^^>output.txt

The only other variant I can think of is to explicitly launch a cmd.exe process to handle the redirection, again with escaped redirection. In this case I think you need three escapes:

start /wait winrs -r:NODENAME -u:USERNAME  -p:PASSWORD cmd /c taskkill /FI \"USERNAME eq USER" /f ^^^^^^^>output.txt

If you want the output redirected to a file on the local machine, then you need to redirect the output of WINRS (assuming WINRS displays the output of the remotely executing process). So just one escape should be required.

start /wait winrs -r:NODENAME -u:USERNAME  -p:PASSWORD taskkill /FI \"USERNAME eq USER" /f ^>output.txt

I'm surprised you need to launch WINRS via START. I should have thought you could execute the command directly, since you plan on waiting for it to finish anyway. If launched directly, and you want the output collected in a local file, then I think you don't need any escape.

winrs -r:NODENAME -u:USERNAME  -p:PASSWORD taskkill /FI \"USERNAME eq USER" /f >output.txt

I'd appreciate a comment as to which, if any, of my suggestions work.

dbenham
  • 127,446
  • 28
  • 251
  • 390
  • EDIT - major rewrite of answer – dbenham Mar 14 '14 at 13:43
  • I confirm that the solution with only one escape ^ put the log on the remote machine and I'm trying to recover the file. Do you think there is a way to redirect on the console output? many thanks – user3419104 Mar 19 '14 at 14:14
  • Really I have a problem producing the file in the machine where the service is running. The file redirected is produced in the machine crrensponding to the node – user3419104 Mar 19 '14 at 16:47
  • @user3419104 - Did you try the last option without START? If so, what happened? – dbenham Mar 19 '14 at 20:13
  • I need to use the start command. I leave the log file on the remote machine. By now it is ok to log on that file what happens. Thanks. – user3419104 Mar 25 '14 at 15:12