PC Review


Reply
Thread Tools Rate Thread

Command results to a file

 
 
Nancy
Guest
Posts: n/a
 
      7th May 2004
At run comand line, we could type DIR or NET VIEW ETC...
and the results are displayed on the screen.
How could I automatically save those results into a text
file?
I tried to do the following:

Dim StreamWriter As StreamWriter
StreamWriter = New StreamWriter(strFN)
StreamWriter.Write(Shell("NET VIEW",
AppWinStyle.NormalFocus, True))
AppWinStyle.NormalFocus, True, 1))
StreamWriter.Close()
NET VIEW is displayed but not saved into the file.
Open for suggestions!
Thanks, Nancy.
 
Reply With Quote
 
 
 
 
AlexS
Guest
Posts: n/a
 
      8th May 2004
Use same approach you would use when doing this in command window: use
redirection. You can create command which redirects output into file in
defined by you location and execute it in same way as you do interactive
variant.
HTH
Alex

"Nancy" <(E-Mail Removed)> wrote in message
news:9f6b01c43457$e2d2a030$(E-Mail Removed)...
> At run comand line, we could type DIR or NET VIEW ETC...
> and the results are displayed on the screen.
> How could I automatically save those results into a text
> file?
> I tried to do the following:
>
> Dim StreamWriter As StreamWriter
> StreamWriter = New StreamWriter(strFN)
> StreamWriter.Write(Shell("NET VIEW",
> AppWinStyle.NormalFocus, True))
> AppWinStyle.NormalFocus, True, 1))
> StreamWriter.Close()
> NET VIEW is displayed but not saved into the file.
> Open for suggestions!
> Thanks, Nancy.



 
Reply With Quote
 
DM McGowan II
Guest
Posts: n/a
 
      8th May 2004
"Nancy" <(E-Mail Removed)> wrote in message
news:9f6b01c43457$e2d2a030$(E-Mail Removed)...
> At run comand line, we could type DIR or NET VIEW ETC...
> and the results are displayed on the screen.
> How could I automatically save those results into a text
> file?
> I tried to do the following:
>
> Dim StreamWriter As StreamWriter
> StreamWriter = New StreamWriter(strFN)
> StreamWriter.Write(Shell("NET VIEW",
> AppWinStyle.NormalFocus, True))
> AppWinStyle.NormalFocus, True, 1))
> StreamWriter.Close()
> NET VIEW is displayed but not saved into the file.
> Open for suggestions!
> Thanks, Nancy.


The best way is to use the Process class and RedirectOutput and
UseShellExecute. Then read from the redirected stream.

Dilton

 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      8th May 2004
Here's a way. Error handling, etc. issues not shown.

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "NET";
psi.Arguments = "VIEW";
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false; // cannot redirect if using shell execute
Process p = new Process();
p.StartInfo = psi;
p.Start();
string s = p.StandardOutput.ReadToEnd();
// do something with the captured output....
Console.WriteLine("Captured output from NET VIEW...\nHere it is:");
Console.WriteLine(s);



"Nancy" <(E-Mail Removed)> wrote in message
news:9f6b01c43457$e2d2a030$(E-Mail Removed)...
> At run comand line, we could type DIR or NET VIEW ETC...
> and the results are displayed on the screen.
> How could I automatically save those results into a text
> file?
> I tried to do the following:
>
> Dim StreamWriter As StreamWriter
> StreamWriter = New StreamWriter(strFN)
> StreamWriter.Write(Shell("NET VIEW",
> AppWinStyle.NormalFocus, True))
> AppWinStyle.NormalFocus, True, 1))
> StreamWriter.Close()
> NET VIEW is displayed but not saved into the file.
> Open for suggestions!
> Thanks, Nancy.



 
Reply With Quote
 
Niki Estner
Guest
Posts: n/a
 
      8th May 2004
From the command line, you would write "NET VIEW > MyFile.txt" to save the
output in a file - did you try executing "CMD NET VIEW > MyFile.txt"? I
think this should work (but didn't test it).

Niki

"Nancy" <(E-Mail Removed)> wrote in
news:9f6b01c43457$e2d2a030$(E-Mail Removed)...
> At run comand line, we could type DIR or NET VIEW ETC...
> and the results are displayed on the screen.
> How could I automatically save those results into a text
> file?
> I tried to do the following:
>
> Dim StreamWriter As StreamWriter
> StreamWriter = New StreamWriter(strFN)
> StreamWriter.Write(Shell("NET VIEW",
> AppWinStyle.NormalFocus, True))
> AppWinStyle.NormalFocus, True, 1))
> StreamWriter.Close()
> NET VIEW is displayed but not saved into the file.
> Open for suggestions!
> Thanks, Nancy.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting results from the Index command Anderson Microsoft Excel Worksheet Functions 1 21st Dec 2007 04:36 PM
Simple for command to get ping results output to file... =?Utf-8?B?TGFycyBQZXRlcnNzb24=?= Microsoft Windows 2000 CMD Promt 3 28th Mar 2007 08:56 AM
Connection is busy with results for another command Lee Schipper Microsoft ADO .NET 2 5th Feb 2004 06:56 AM
Capture the results of a Windows explorer Search file and save the results Larry Frazin Microsoft Windows 2000 Printing 0 17th Sep 2003 10:07 PM
FAT32 weird Dir command results Kevin Hatfield Microsoft Windows 2000 File System 2 15th Sep 2003 08:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:00 PM.