quote:
Originally posted by SmokingCookie
You'll need to output some stuff that is known to your script; things it'll be looking for. An example:
Batch code:
ECHO !BEGINBATCH! >> Output.txt
@ECHO OFF
ECHO !ENDCOMMAND! >> Output.txt
ipconfig /all >> Output.txt
ECHO !ENDCOMMAND! >> Output.txt
DIR C:\ >> Output.txt
ECHO !ENDCOMMAND! >> Output.txt
ECHO !ENDBATCH! >> Output.txt
Then have the script load the file and search for "!BEGINBATCH!", "!ENDCOMMAND!" and "!ENDBATCH!".
NB you'll need to know where Output.txt is located. I don't really know where you'll find it; you'll need to experiment with that.
Such a batch file is not needed. It is making things way too limited and too complicated.
If you take the "
redirecting the command line" approach (which is already a complicated thing if you want to do it right), 'all' you need to do is to add something like ">
UNIQUENAME.TXT" to the command line you've send to your remote pc.
------------------
Note that that is just a simply example, the stuff you actually need to add will be a bit more complicated as you also need to catch errors and messages which are not send to the standard output but to the secondary error stream. People who often work in DOS know what I mean; eventhough you used "> file.txt" sometimes stuff will still be printed on the screen.
eg: do "dir :: > file.txt".
So, you actually need to add "> UNIQUENAME.TXT 2>&1" to also redirect the STDERR stream to the STDOUT stream.
UNIQUENAME must be unique, as you do not want to overwrite an existing output file from a previous command which is still running.
------------------
But the hard part is that you need to wait until the command has finished before you can open the output file and send it. And if you get the command wrong, it might even be that the process will never end to begin with. Also some commands do require keyboard input (eg: "dir /p"). It speaks for its own that doing such commands (even by accident!) will render the whole process useless and the script running this will hang and probably take messenger with it.
But all in all, using this method is very limited; you can only do so much with the command line, and constantly needing to send output files doesn't work that well in practice. So, the method is a very dodgy way of doing things, because...
...If you have only a fixed set of commands you want to use, you far better use Windows APIs to do the stuff directly.
...And if you're not sure about what commands you're going to need (or want to do stuff like file and directory manipulations - you said you want to use DIR, COPY, DEL, etc), I strongly recommend using a Remote Desktop software. There are a lot of free and small Remote Desktop softwares available on the net, not to mention that it is also already available in Windows and directly accessable from Messenger. It has also the benefit that you would still be able to access your remote pc and do stuff when Messenger has problems logging in, etc. Imagine you're doing some file/dir maintenance and suddenly Messenger disconnects, then you're screwed... With remote desktopping you wont have that problem.