473,508 Members | 2,216 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Command results to a file

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.
Jul 21 '05 #1
4 1411
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" <an*******@discussions.microsoft.com> wrote in message
news:9f****************************@phx.gbl...
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.

Jul 21 '05 #2
"Nancy" <an*******@discussions.microsoft.com> wrote in message
news:9f****************************@phx.gbl...
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

Jul 21 '05 #3
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" <an*******@discussions.microsoft.com> wrote in message
news:9f****************************@phx.gbl...
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.

Jul 21 '05 #4
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" <an*******@discussions.microsoft.com> wrote in
news:9f****************************@phx.gbl...
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.

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1935
by: Ben Floyd | last post by:
It goes like this: Im converting a perl script that executes a command on each result of a directory listing. In perl, all is well. In Python, using approximately the same logic creates a...
4
9872
by: Kartik | last post by:
Hi, I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file. This is achieved using xp_cmdshell Dim str As String = "xp_cmdshell...
4
313
by: Nancy | last post by:
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:...
9
19669
by: shank | last post by:
What is the proper syntax to run this command line in ASP? wzzip.exe File.zip File.txt thanks
6
1299
by: djc | last post by:
I'm wondering what options are available, if any, for being able to run 'any command line command' from a .net compiled program. I would want the output that would normally go to the command line...
3
10306
by: jlw16 | last post by:
Hello, I’m trying to use my vbs script to get a command line argument for a file which will need to be opened through QuickTestPro. Below are the commands I’m using: Dim qt_file 'As String ->...
10
6086
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the...
0
1297
by: ebindia0041 | last post by:
Any help what is wrong with this code.. I am tring to FTP post a file by command prompt but it not work, system hang up.. commands are in my batch file... System.Diagnostics.ProcessStartInfo psi...
5
8315
by: rohitkumar | last post by:
I am trying to build a web application which can execute dos print command on the client machine. This application will read a file stored in server and it will create a folder on client machine...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.