Does anyone know how you would make, using c++, basic, batch programming, or any language :-p, a program that would run a windows command in cmd.exe, and then save the output to a text file? Thanks for any help. :)
Printable View
Does anyone know how you would make, using c++, basic, batch programming, or any language :-p, a program that would run a windows command in cmd.exe, and then save the output to a text file? Thanks for any help. :)
Greetings:
A simple 1 line batch file can do the trick:
command > file.txt
save it as Program.bat and execute =)
note: it will replace file.txt each time it's run. if you'd rather it append the results to the file, instead of replacing it completely, use >> instead of >
I'll just show a basic command line way here (for dos/win) that could also be placed in a batch file. What you need to do is use output redirection. Sounds difficult? well, it isn't.
anycommand > data.txt (could be dir /a > files.txt)
this type of redirection creates a file named "data.txt" and the output from "anycommand" would be written in that file. This method would delete any existing file named data.txt that is is the current directory.
now, using anycommand >> data.txt (could be dir /a >> files.txt) is called "appending" because it adds "anycommand" 's output to the end of the file "data.txt".
I think it also works this way in linux (at least using bash) but you have the ability to suck out the error messeges also (check out a linux/unix book for more information)
For basic... well i know it works in qbasic... you could do the same by executing the shell function (check out qbasic's help file for more information)
Enjoy
Thank you! :-D This is exactly what I was looking for. :D
Hmmmmmm. Would there be anyway to sent the output of the text file or the text file itself to another computer running a telnet server that would bring up a command prompt when telnetted to?
Edit: Also, Is there any way to turn a batch file into a .exe?
Why would you want to do that?
I am not particularly happy with the direction we are going here?............has even the "great JP" been suXsor3d?
Thoughts?
I'm with Nihil on this one...
Jared, let us know what you're trying to accomplish - your questions will be received much better. As for turning the batch file into an executable, well, that's simple...
C:\>ren file.bat file.exe
-Wiski C.
I have a computer on my network in my basement with no monitor. :cool: lol. I can run files though by making a cd-rom with an autorun file that runs a batch or an exe, or I can carry one monitor back and forth, but that is a pain. :(
Edit: When you rename a .bat file .exe and run it, it just outputs some messed up text.
Its much easier to just use a remote desktop tool...Quote:
Originally posted here by Jareds411
I have a computer on my network in my basement with no monitor. :cool: lol. I can run files though by making a cd-rom with an autorun file that runs a batch or an exe, or I can carry one monitor back and forth, but that is a pain. :(
Edit: When you rename a .bat file .exe and run it, it just outputs some messed up text.
Look into VNC.
You'll save yourself a lot of time and trouble.
You can't rename a .bat to a .exe and expect it to work.
A .bat is just a batch file.
A .exe is a binary file. When you compile source code... the output is a .exe (not all the time... but at least on windows using something like c or c++)
I know that, but I was replying to wiskic10_4 who told me that when I asked earlier if there was any way to convert a batch file to an exe.Quote:
Originally posted here by phishphreek80
You can't rename a .bat to a .exe and expect it to work.
A .bat is just a batch file.
A .exe is a binary file. When you compile source code... the output is a .exe (not all the time... but at least on windows using something like c or c++) [/B]