Larry Brister
asked on
VB Code write cmd.exe to file
I have a process that works.
On a button click it (WIth hidden widnow)
Runs cmd.exe
executes a java command
The cmd.exe is using an append to file with > myfile.txt
The process runs...opens a connection to my vendor and starts receiving the inbound data
Now this is an open connection so as long as this runs I will get a continuous stream of telephone data on our network.
(No...I don't work for the NSA...LOL)
I allso have a process.kill() command.
WHat I want is for this to continuously append to the file
BUt it looks like the file isn't written until I kill the process?
Is that the way it works?
I really need it going into the file in an ongoing manner
This is what is running
On a button click it (WIth hidden widnow)
Runs cmd.exe
executes a java command
The cmd.exe is using an append to file with > myfile.txt
The process runs...opens a connection to my vendor and starts receiving the inbound data
Now this is an open connection so as long as this runs I will get a continuous stream of telephone data on our network.
(No...I don't work for the NSA...LOL)
I allso have a process.kill() command.
WHat I want is for this to continuously append to the file
BUt it looks like the file isn't written until I kill the process?
Is that the way it works?
I really need it going into the file in an ongoing manner
This is what is running
Private Sub btnProcessStart_Click(sender As System.Object, e As System.EventArgs) Handles btnProcessStart.Click
' New ProcessStartInfo created
Dim p As New ProcessStartInfo
' Specify the location of the binary
p.FileName = "cmd.exe"
p.WorkingDirectory = "C:\Program Files (x86)\Java\jre7\bin\"
' Use these arguments for the process
p.Arguments = "/c java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar > C:\temp\Output3.txt"
' Use a hidden window
p.WindowStyle = ProcessWindowStyle.Hidden
' Start the process
Process.Start(p)
Dim intResponse As Integer
intResponse = MsgBox("End?", vbYesNoCancel, "Alert")
If intResponse = vbYes Then
For Each jr In Process.GetProcessesByName("Java")
Try
jr.Kill()
Catch
End Try
Next
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
CodeCruiser
On the StackFlow site...
Which of those solutions should I be using? I see 9 answers
On the StackFlow site...
Which of those solutions should I be using? I see 9 answers
The first one.
And the alteration will be something like this:
And the alteration will be something like this:
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "YOURBATCHFILE.bat";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadLine();
string line = string.Empty;
while ((line = p.StandardOutput.ReadLine()) != null)
{
output = line;
}
p.WaitForExit();
Sorry it's for VB!
Dim p As New Process()
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.FileName = "YOURBATCHFILE.bat"
p.Start()
Dim output As String
Dim line As String
While ((line = p.StandardOutput.ReadLine()) != Nothing)
output = line
End While
p.WaitForExit()
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
CodeCruiser
As always...thanks
As always...thanks
whats data do u wanna write to a file?