asp: reacting to output on page

rh71

No Lifer
Aug 28, 2001
52,844
1,049
126
I have an ASP page with a function (that's written in an include) that grabs output from another server and displays it right on the ASP page using response.write. The function uses 'psexec' to interact with a command prompt of another server. PSEXEC is a command-line remoting executable that is capable of bringing output back to your machine.

What I want to do is depending on the output that comes back on the ASP page, I want it to display something to the effect of success or failure.

Right now, it displays "OK: completed successfully" or "ERROR: 0x222 name not found" just fine on the ASP page. I want to display more depending on either of those. If it's the latter, I'd display "failure" on the page.

I am not savvy enough to grab this output from the function and read/react to it using something like inStr(). The output is obviously within the response.write(myfunction()). I've tried referring to the var in the function itself but inStr() doesn't seem to read it correctly and thus doesn't react with either of my conditions - no errors either. Is there some other method of doing this? Am I on the right track here? Can you write up a quick example of how it should be done?
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
The output of myfunction() is probably a string. So try something like this to start with:

string s = myfunction();
s = s.Replace("OK: completed successfully", "My custom message");
s = s.Replace("ERROR: 0x222 name not found", "Another custom message");
Response.Write(s):

If the match string isn't found Replace() returns the original string, so you can add additional lines for other messages you want to replace. There's a performance cost to this, and there may be better ways to do it based on more knowledge of how psexec() works, but this is a start.