Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


running a dos command

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,54630
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> running a dos command
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 running a dos command - 12/20/2007 3:26:54 AM   
  pelegk2

 

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

 
 
Post #: 1
 
 RE: running a dos command - 12/20/2007 3:43:47 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
I would suggest piping just the netstat to a file then use VBScript to do the findstr.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to pelegk2)
 
 
Post #: 2
 
 RE: running a dos command - 12/20/2007 4:17:27 AM   
  morpheus83uk

 

Posts: 435
Score: 0
Joined: 8/21/2006
Status: offline
Hello,

Here try this:


      

Hope this helps

James

(in reply to pelegk2)
 
 
Post #: 3
 
 RE: running a dos command - 12/20/2007 9:13:39 AM   
  pelegk2

 

Posts: 79
Score: 0
Joined: 3/27/2005
From: Israel
Status: offline
ebgreen : i tried o do it withought the "|findstr 337 " and it didnt work

morpheus83uk : itried your code and only a new dos window was opened - what did u try to do
??

 
thnaks
peleg

(in reply to morpheus83uk)
 
 
Post #: 4
 
 RE: running a dos command - 12/20/2007 9:32:30 AM   
  ehvbs

 

Posts: 2223
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi pelegk2,

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)

ehvbs

(in reply to pelegk2)
 
 
Post #: 5
 
 RE: running a dos command - 12/20/2007 10:33:25 AM   
  morpheus83uk

 

Posts: 435
Score: 0
Joined: 8/21/2006
Status: offline
ehvbs,
 
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... :)

Hope this gets you sorted :)

Thanks

James
 

(in reply to ehvbs)
 
 
Post #: 6
 
 RE: running a dos command - 12/20/2007 10:57:01 AM   
  ehvbs

 

Posts: 2223
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi morpheus83uk,

don't mention it!

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"

Regards

ehvbs

(in reply to morpheus83uk)
 
 
Post #: 7
 
 RE: running a dos command - 12/20/2007 11:04:03 AM   
  pelegk2

 

Posts: 79
Score: 0
Joined: 3/27/2005
From: Israel
Status: offline
well my mistake i forgot to switch to a por the dose currently exist :)
else i got the empty answer!

thnaks all of u
peleg

(in reply to ehvbs)
 
 
Post #: 8
 
 RE: running a dos command - 12/20/2007 11:18:35 PM   
  morpheus83uk

 

Posts: 435
Score: 0
Joined: 8/21/2006
Status: offline
ehvbs

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 :)

Thanks Again

James

(in reply to ehvbs)
 
 
Post #: 9
 
 RE: running a dos command - 12/20/2007 11:43:46 PM   
  ehvbs

 

Posts: 2223
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi morpheus83uk,

perhaps using the code tags will help.

Regards

ehvbs

(in reply to morpheus83uk)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> running a dos command Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts