Thanks for the quick reply aGerman. I just used finding a file as an example to make things simpler to explain.
Since I have your attention, maybe you can still help.
I am ultimately trying to to execute commands on remote machines conveniently. I thought psexec would work (System Internals utility), however, I kept getting the below errors even when the syntax was correctERROR: Input redirection is not supported, exiting the process immediately.
So, I thought I would make my own psexec replacement revolved around wmic. I am able to use psexec.cmd (code below). However, if a file takes too long to process, I get the error message that the temp file is still being used by the process (temp file is still being written)
I figured out a way to detect when the file is no longer in use. But then to my horror.. I realized I AM GET THE SAME DAMN ERROR I did using the System Internals utility!!!ERROR: Input redirection is not supported, exiting the process immediately.
aGerman, could you please help me to avoid that error. I don't even know exactly why it's happening. I just want a reasonable solution to return the output of a command I execute on a remote machine; even if the output takes several seconds to finish.
Code for PSexec.cmd
usage syntax Examples:
\\servername command arg arg arg
servername command blah blah blah
FOR /F "tokens=1,*" %%A in ("%*") do (
if %UserInput:~0,2%==\\ (
wmic /node:%UserInput% process call create "cmd.exe /c %command% >C:\Windows\Temp\rexec.tmp" 1>NUL 2>&1
move \\%UserInput%\C$\Windows\Temp\rexec.tmp \\%UserInput%\C$\Windows\Temp\rexec.tmp 2>NUL >NUL
if %errorlevel%==1 timeout /t 1 >nul &goto tryagain
del /q \\%UserInput%\C$\Windows\Temp\rexec.tmp >nul