S
ShieldsJared
Hello all,
So I recently found out about redirecting the Standard Output of a
vbscript back to my C# app but I've found a problem.
When I run a script that calls OpenTextFile, I do not receive anymore
of the standard output after that call is made.
Here is my code:
------------------------------------------------------------------------------------------------------
C#
------------------------------------------------------------------------------------------------------
public void Run(string path, string title)
{
//used to prevent output of the initial csript output
bool write = false;
string scriptName = path;
ProcessStartInfo si = new
ProcessStartInfo("cscript.exe", scriptName);
si.RedirectStandardOutput = true;
si.RedirectStandardError = true;
si.UseShellExecute = false;
si.WindowStyle = ProcessWindowStyle.Hidden;
si.CreateNoWindow = true;
OutputBox.Clear();
Process p = Process.Start(si);
while (true)
{
string s = p.StandardOutput.ReadLine();
if (s == null
{
break;
}
//Allows me to skip past the initial headings from a
VBScript output via CSript.exe (this isn't the problem)
else if (s == "<<StartOutput>>")
{
write = true;
s = title + " started at " + DateTime.Now;
}
if(write)
OutputBox.AppendText(s);
}
return true;
}
---------------------------------------------------------------------------------------------------
VBScript
---------------------------------------------------------------------------------------------------
' Include Library Script
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
set oFile = fso.OpenTextFile("Tools.vbs",1)
sText = oFile.ReadAll
oFile.close
ExecuteGlobal sText
'Output
Wscript.Echo "<<StartOutput>>"
WScript.Echo "Yeah!"
Wscript.Echo "<<EndOutput>>"
---------------------------------------------------------------------------------------------------
Basically, If I comment out everything except for the CreateObject,
and the Echo's, the C# app picks up the Echo's just fine. As soon as
I uncomment the OpenTextFile.... The application only receives the
output regarding the initial startup of CScript.exe, but nothing
else..
Any ideas?
Thanks so much!
So I recently found out about redirecting the Standard Output of a
vbscript back to my C# app but I've found a problem.
When I run a script that calls OpenTextFile, I do not receive anymore
of the standard output after that call is made.
Here is my code:
------------------------------------------------------------------------------------------------------
C#
------------------------------------------------------------------------------------------------------
public void Run(string path, string title)
{
//used to prevent output of the initial csript output
bool write = false;
string scriptName = path;
ProcessStartInfo si = new
ProcessStartInfo("cscript.exe", scriptName);
si.RedirectStandardOutput = true;
si.RedirectStandardError = true;
si.UseShellExecute = false;
si.WindowStyle = ProcessWindowStyle.Hidden;
si.CreateNoWindow = true;
OutputBox.Clear();
Process p = Process.Start(si);
while (true)
{
string s = p.StandardOutput.ReadLine();
if (s == null
{
break;
}
//Allows me to skip past the initial headings from a
VBScript output via CSript.exe (this isn't the problem)
else if (s == "<<StartOutput>>")
{
write = true;
s = title + " started at " + DateTime.Now;
}
if(write)
OutputBox.AppendText(s);
}
return true;
}
---------------------------------------------------------------------------------------------------
VBScript
---------------------------------------------------------------------------------------------------
' Include Library Script
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
set oFile = fso.OpenTextFile("Tools.vbs",1)
sText = oFile.ReadAll
oFile.close
ExecuteGlobal sText
'Output
Wscript.Echo "<<StartOutput>>"
WScript.Echo "Yeah!"
Wscript.Echo "<<EndOutput>>"
---------------------------------------------------------------------------------------------------
Basically, If I comment out everything except for the CreateObject,
and the Echo's, the C# app picks up the Echo's just fine. As soon as
I uncomment the OpenTextFile.... The application only receives the
output regarding the initial startup of CScript.exe, but nothing
else..
Any ideas?
Thanks so much!