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]
Or even better yet, go on Ebay and purchase yourself a crappy monitor. They have ones you can pick up there for under $50, so all but the most ghetto of techies can afford one. If you are one of those sad cases of an extremely ghetto techie, then start looking up yard sales in the Sunday paper. I'm sure if you shopped around you could find an old one that someone's getting rid of for next to nothing.Quote:
Originally posted here by phishphreek80
Its much easier to just use a remote desktop tool...
Look into VNC.
You'll save yourself a lot of time and trouble.
...or if you cant afford garage sales take a walk/ride threw a nicer neighbor hood on large item garbage day. usually the same day every month in towns that can afford it. these guys throw out good moniters when they decide its time for a new one. you can find good p-II/III machines just tossed!?!
If the remote machine is a windows box look into pstools from sysinternals.
It contains a vary handy tool called psexec. pstools need NT4 or better though.
This will start a remote cmd prompt
psexec \\remotecomputer cmd
As for outputting a textfile to another pc take alook at netcat.
nc remote.computer 23 < textfile.txt should do the trick.
A better way would be to use SSH.
This way you'll have strong authentication and encryption.
scp mytextfile.txt [email protected]uter:some/directory
Hell, you can have one of the 20 or so I have collecting dust in my basement.
I tried that, and it doesn't work. :confused:Quote:
Originally posted here by SirDice
As for outputting a textfile to another pc take alook at netcat.
nc remote.computer 23 < textfile.txt should do the trick.
Soooo...you DO have Netcat installed on your PC? It's not one of those built in commands, you know...
You know what you could do... Seeing as how you have physical access and all, you could write a program that updates the file you want after so much time, then run some server software on the remote machine. I would suggest a webserver, that way you could design the program to format your log output in to some nice HTML. I've done this for a "Today in History" program, which goes through a large database of comma delimited textfiles, extracts the appropriate data, catagorizes, and formats the data into HTML. The page is output to a directory of my server, and hosted to the local network.
This solves the problem of having to swap monitors, run the program manually, and get the information remotely.
Hope this helps!
(P.S. - I might be willing to help out depending on the motive of the project.)
Yep, I have netcat in c:\windows\system32 in bolth computers. I've used it before, so I know it works.
I don't have any idea how to go about any of that, and I think I'd be pretty much lost. :rolleyes:Quote:
Seeing as how you have physical access and all, you could write a program that updates the file you want after so much time, then run some server software on the remote machine. I would suggest a webserver, that way you could design the program to format your log output in to some nice HTML. I've done this for a "Today in History" program, which goes through a large database of comma delimited textfiles, extracts the appropriate data, catagorizes, and formats the data into HTML. The page output to a directory of my server, and hosted to the local network.
It's not that bad. Just install the server software (Sambar is easier), then run a program that does the following:
In QB:
SHELL "[command] > \sambar\docs\outputfile.html";
----
Have it do at a certain time of the day, or after a certain increment of time, and it will be pretty much self-sufficient, as long as the program is running.
You could then place shortcuts to the server and the program in your startup directory, so that it starts up every time you have to reboot the computer.
Lol idk how to do that either.Quote:
Originally posted here by embro1001
Have it do at a certain time of the day, or after a certain increment of time, and it will be pretty much self-sufficient, as long as the program is running.
i think vnc is really your answer but quit frankly...im not sure i know the question. what in hell are you trying to do.
you can turn a .bat into an executable with a proggie called (oddly enough) bat2exe. just say in plain language what your trying to do and you will get a workable solution...whadda ya got to lose?
Ok. I have a solution to your problem. If you read back, I suggested using a program in conjunction with a webserver to deliver you live content. Seeing as how you don't have the know-how in this particular area (everyone has their specialties), I took it upon myself to write the program for you.
Took me about an hour in QB. Just follow the instructions in the readme. Basically, run the program, give it the needed parameters, and fire up your web browser. If you need help, my email is in the readme.
VNC is nice, but not very efficient. He has to log in and load each time, and the lag isn't always user friendly. My option gives him the opportunity to save results on his local machine.
one more thing.by using the bat2exe prog you will tansform your .bat file to .com file.
if you want to make your bat file uneditable or unreadable then you won't achieve that by using bat2exe.....
if you try to right click and edit a .com file you can still figure out what it does....
you see bat2exe isn't a compiler...as far as i know....
I used b2e, and it did have the problem of not hiding source. I fixed it by going into my c++ compiler and using the command : system("command here"); to make the batch file, then compiling int. Embro1001, Thanks! That program works perfectly. :-)
Glad to hear it.....see it...whatever. If you need any more custom proggies, email me and I will do my best to help (this applies to anyone).