Posts: 79
Score: 0
Joined: 3/27/2005
From: Israel
Status: offline
i want to write a netstat command into a log files from vbscript i tried to do :
and it dosent work ** i also tried to called a bat files with the path to the file as a parameter but i get a message that the file is looked by another process (where the files was never created yet!) and it dosent work too! what can i do? thnaks i nadvance peleg
if you want to use piping (|) and/or device rerouting (>, >>, <), you need a shell - invoked by %comspec% in your command string. morpheus83uk's code does this and I bet that there is a file c:\test\1.log containing some output on your machine.
The parameter /K is responsible for not closing the dos box. Use /C to close it after doing the work.
Good luck! (to you for getting the info, to me for winning the bet)
Thanks for that just returned in and I noticed I had left the /K switch in there which I was using for testing as the original code just threw up a command window and then bombed out so I changed it!! Should have really changed it back but you got there before me :)
pelegk2 - If you give the code a go and have a look in the c:\test folder I am sure you will have the expected output as it works very well on my machine when I use a port which is in use for testing... :)
Having kind of defended your code, I feel I've earned the right to do a bit of my nit picking. Please look at the following as "this is how it sounds on my guitar what you just played on your piano", not as "Do it my way or else".
(1) Indentation isn't just for nice looks; it helps to write and to understand source code.
(2) "Say it once" / "Don't double code" isn't just for lazy programmers. It reduces the risk of errors and improves the chances of efficient comprehension.
If Not objfso.FolderExists("C:\Test") Then objfso.CreateFolder("C:\Test") End If objshell.Run "%comspec% /K c: & netstat -n -p tcp |findstr 443 > c:\test\1.log"
Thanks for that and yes I will let you nit pick as its always good for learning...
Indentation is indeed good however I have found when I copy and paste code from within the little code boxes it does not seem to indent in sat primalscript or anything or if I have it indented I cant seem to see it that way on screen... might just be me when I look at it I dont see it as pretty as I do in my editor lol
As for your second point I thank you I will indeed try to keep my code much cleaner in the future :)
pelegk2 - Glad to hear you have it all working now :)