so currently what I am attempting to do is, remote onto a different server, launch a scheduled task, exit, change to a specified folder on my desktop, write a file
My code currently looks as such
C:MyOriginalFolder> psexec \\MYREMOTESERVER -u MYUSERNAME cmd
C:MYREMOTESERVER> SCHTASK.......
C:MYREMOTESERVER> exit & cd C:\\Users\ce132d & echo "Logged off" > MyLog.txt
//expected: the folder C:\\Users\ce132d should have a text file called MyLog.txt
//what happens: I end up in C:MyOriginalFolder with no MyLog.txt file created
When I remove the &’s and test it command by command, all is dandy and the expected behavior happens. But when linking them together with & and &&, the expected behavior does not happen.
So my question is this: is there some way of one-lining the actions of exiting, changing directory, and writing a text file?
I am eventually going to check if loging into the remote server was successful or not, and want to put those 3 actions into a if (successful login) {do 3 tasks} else {write error log}..
You send your remote server
exit & cd C:\\Users\ce132d & echo "Logged off" > MyLog.txt.Why do you expect that the
cd ...should have any effect on your local directory?When you send the commands line by line then your
exitwill EXIT the remote server context, then you are again on your local machine, therefore the rest of the commands works as expected.