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! 2 5000
<Sh**********@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
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!
My guess is that the script host terminates execution because of an error.
try this:
On Error Resume Next
...
set oFile = fso.OpenTextFile("Tools.vbs",1)
if err.number <0 then
Wscript.Echo Err.Description
End If
Willy.
Willy, you are awesome. That completely worked! The wierd thing is,
the script ran fine when i ran the script on it's own. It only
recieved the error when I called it from my C# App. Oh well. I added
the full path to the file and now it works beautifully.
Thanks for your help! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jwallison |
last post by:
XPSp1/IIS 5.1
What am I doing wrong? The following code just hangs in asp page at
OpenTextFile() - and inet service manager just hangs if I try to unload app
at
this point -
<script...
|
by: Fie Fie Niles |
last post by:
In my ASP (IIS 5.1), when I use oFile.OpenTextFile to open a file, the code
stucks.
How can I fix this problem? Thanks.
set oFile = CreateObject("Scripting.FileSystemObject")
strServerFileName...
|
by: Simon K |
last post by:
I'm trying to write a .txt file with OpenTextFile method. This is working
alright, but since I'm using some danish characters and use Flash to read
the txt file I need to save the file as UTF-8 or...
|
by: Serge Myrand |
last post by:
Hi,
I cannot use the OpenTextFile method, it's never return and I get no
error message! Setting Response.Buffer=False, has no effect. No matter
if I use it ForReading or ForWriting, it never...
|
by: wolftor |
last post by:
After I use Access 2K Developer to package and deploy, and then when
installing the application that was packaged, I get screens that say:
Version Conflict
A file being copied is not newer than...
|
by: Dhruba Bandopadhyay |
last post by:
I am a current ASP developer.
I have files: ServiceClass.asp & SessionClass.asp which are included in many
of my asp files. Then they call objService = New Service (by using the Class
Service...
|
by: itskaps |
last post by:
Hi all,
My following program code works fine on win 2K server but the same is not working on win2K3 server. It's showing error as page cannot be displayed. After debugging, I found that...
|
by: angelina18 |
last post by:
Hi. This is my first post here and my first css site. I read alot of the previous posts and therefore I did validate my code, but I couldn't find the answers to my 2 problems which are:
1. When I...
|
by: Taras_96 |
last post by:
Hi all,
A poster at http://bytes.com/forum/thread60652.html implies that using
strtoupper in transform doesn't work because ctype.h may define
strtoupper as a macro:
"The problem is that most...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |