By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,591 Members | 1,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,591 IT Pros & Developers. It's quick & easy.

Problem with Shell() function in vb.net with complex command string

P: n/a
I have been trying for days to send a command to the command prompt
through the shell() function in vb.net. For some reason it is not
working. Here is the code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim command As String

command = "systeminfo > C:\temp\sysinfo.txt"

Shell(command, AppWinStyle.MaximizedFocus)
'Process.Start(command)

End Sub

As you can tell I have tried it with Shell() and process.start(). I
have also tried to use double quotes throughout different parts of the
string. When the code executes the command window flashes but the file
is not created. When I paste the command in the command window
everything works fine. Can anyone help?

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

<mi***********@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I have been trying for days to send a command to the command prompt
through the shell() function in vb.net. For some reason it is not
working. Here is the code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim command As String

command = "systeminfo > C:\temp\sysinfo.txt"

Shell(command, AppWinStyle.MaximizedFocus)
'Process.Start(command)

End Sub

As you can tell I have tried it with Shell() and process.start(). I
have also tried to use double quotes throughout different parts of the
string. When the code executes the command window flashes but the file
is not created. When I paste the command in the command window
everything works fine. Can anyone help?


This is a meta-ness problem. The ">" is not an argument to systeminfo, but
rather to the command interpreter. Anyway, to make this work, invoke the
command shell explicitly, telling it to execute the command "systeminfo >
C:\temp\sysinfo.txt" and then exit:

Sub Main()
Dim command As String
command = "cmd /c systeminfo > C:\temp\sysinfo.txt"
Shell(command, AppWinStyle.MaximizedFocus)
'Process.Start(command)
End Sub

You could also just redirect standard output for the program, and skip the
file.

David
Nov 21 '05 #2

P: n/a
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> schrieb:
You could also just redirect standard output for the program, and skip the
file.


Sample:

<URL:http://dotnet.mvps.org/dotnet/samples/misc/RedirectConsole.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.