Piping results of command line call to file from ASP 
Author Message
 Piping results of command line call to file from ASP

I've got an ASP page on Windows 2000 Server that needs to check for
any orphaned Excel processes before it runs.  However, when I run the
ASP page below, I can't seem to get "tlist" to write out the results
to the file "c:\test.txt" as shown below.  But, if I comment out the
command line for "tlist" and instead use the call to "nbstat" - PRESTO
- the results are in the file.

Furthermore, if I simply sit down on the web server and run the same
command line for "tlist" from the console

"cmd /c tlist -p excel.exe > c:\test.txt"

it DOES write out the results to the file.

Any ideas why results from a call to "tlist" write to the file when
called  directly from the console, but not from the ASP page?  As you
can see, calls to "nbstat" (or "dir", or any number of other commands)
actually write results to the file when called from the console AND
when called from ASP...

I can't seem to find anything on Microsoft's site indicating why tlist
should function any differently than any other call.

(NOTE:  "tlist.exe" can be installed by installing server tools from
Windows 2000 Server CD (look in Support\Tools folder and run
"setup.exe")

Thanks.

<%

Dim oWShell, oFS, TempName, OutputText

Set oWShell = CreateObject("WScript.Shell")
TempName = "c:\test.txt"

'Here are the two commands to test:

'Test 1:

'Cmd = "cmd /c tlist -p excel.exe > " & TempName
'Result should be:
'    -1    ---  if excel.exe is not running or
'    640   ---  (or other correct PID) if running

'Test 2:

Cmd = "cmd /c nbtstat -A > " & TempName
'Result should be:  
'         Local Area Connection: Node IpAddress: [123.456.789.012]
Scope Id: []

oWShell.Run Cmd, 0, True
Set oFS = CreateObject("Scripting.FileSystemObject")
OutputText = oFS.OpenTextFile(TempName, 1, True).ReadAll
oFS.Close

Set oFS = Nothing
Set oWShell = Nothing

Response.write("Output of call is: " & OutputText & "<br>")

%>



Wed, 07 Jul 2004 01:32:39 GMT  
 Piping results of command line call to file from ASP
Most likely the path to tlist is wrong relative to the current directory of
the ASP page. Try putting in the absolute path to tlist and see if that
corrects the problem.

ex.
<%
Dim WshShell

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd /c ""C:\Program Files\Support Tools\tlist.exe"" -p
dllhost.exe > c:\tlist.txt"
Set WshShell = Nothing
%>

Mike Dutra
Windows Script Host Support

This posting is provided AS IS with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.

--------------------

Quote:

>Newsgroups:

microsoft.public.scripting.VBScript,microsoft.public.scripting.wsh
Quote:
>Subject: Piping results of command line call to file from ASP
>Date: 18 Jan 2002 09:32:39 -0800

>I've got an ASP page on Windows 2000 Server that needs to check for
>any orphaned Excel processes before it runs.  However, when I run the
>ASP page below, I can't seem to get "tlist" to write out the results
>to the file "c:\test.txt" as shown below.  But, if I comment out the
>command line for "tlist" and instead use the call to "nbstat" - PRESTO
>- the results are in the file.

>Furthermore, if I simply sit down on the web server and run the same
>command line for "tlist" from the console

>"cmd /c tlist -p excel.exe > c:\test.txt"

>it DOES write out the results to the file.

>Any ideas why results from a call to "tlist" write to the file when
>called  directly from the console, but not from the ASP page?  As you
>can see, calls to "nbstat" (or "dir", or any number of other commands)
>actually write results to the file when called from the console AND
>when called from ASP...

>I can't seem to find anything on Microsoft's site indicating why tlist
>should function any differently than any other call.

>(NOTE:  "tlist.exe" can be installed by installing server tools from
>Windows 2000 Server CD (look in Support\Tools folder and run
>"setup.exe")

>Thanks.

><%

>Dim oWShell, oFS, TempName, OutputText

>Set oWShell = CreateObject("WScript.Shell")
>TempName = "c:\test.txt"

>'Here are the two commands to test:

>'Test 1:

>'Cmd = "cmd /c tlist -p excel.exe > " & TempName
>'Result should be:
>'    -1    ---  if excel.exe is not running or
>'    640   ---  (or other correct PID) if running

>'Test 2:

>Cmd = "cmd /c nbtstat -A > " & TempName
>'Result should be:  
>'         Local Area Connection: Node IpAddress: [123.456.789.012]
>Scope Id: []

>oWShell.Run Cmd, 0, True
>Set oFS = CreateObject("Scripting.FileSystemObject")
>OutputText = oFS.OpenTextFile(TempName, 1, True).ReadAll
>oFS.Close

>Set oFS = Nothing
>Set oWShell = Nothing

>Response.write("Output of call is: " & OutputText & "<br>")

>%>



Wed, 07 Jul 2004 04:32:37 GMT  
 Piping results of command line call to file from ASP
Thanks for the help.  That solved that problem.  Now I'm running into
unexpected trouble with kill.exe.  Seems kill.exe is working fine from
the console, but not ASP.  Response I get when calling from ASP is

process EXCEL.EXE (1160) - '' could not be killed

I've tried it with and without the -f option as well as with PID and
process name.  Same result.
Here's the code and thanks again.

<%

Dim oWShell, TempName

Set oWShell = CreateObject("WScript.Shell")
TempName = "c:\test.txt"

Cmd = "cmd /c ""C:\Program Files\Support Tools\kill.exe"" excel.exe > "
& TempName
'Cmd = "cmd /c ""C:\Program Files\Support Tools\kill.exe"" -f 1160 > " &
TempName

oWShell.Run Cmd, 0, True

Set oWShell = Nothing

%>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Wed, 07 Jul 2004 07:37:16 GMT  
 Piping results of command line call to file from ASP
Might need to check the permissions under which the ASP page is processed.
May not have access to the thread information.

-K


Quote:
> I've got an ASP page on Windows 2000 Server that needs to check for
> any orphaned Excel processes before it runs.  However, when I run the
> ASP page below, I can't seem to get "tlist" to write out the results
> to the file "c:\test.txt" as shown below.  But, if I comment out the
> command line for "tlist" and instead use the call to "nbstat" - PRESTO
> - the results are in the file.

> Furthermore, if I simply sit down on the web server and run the same
> command line for "tlist" from the console

> "cmd /c tlist -p excel.exe > c:\test.txt"

> it DOES write out the results to the file.

> Any ideas why results from a call to "tlist" write to the file when
> called  directly from the console, but not from the ASP page?  As you
> can see, calls to "nbstat" (or "dir", or any number of other commands)
> actually write results to the file when called from the console AND
> when called from ASP...

> I can't seem to find anything on Microsoft's site indicating why tlist
> should function any differently than any other call.

> (NOTE:  "tlist.exe" can be installed by installing server tools from
> Windows 2000 Server CD (look in Support\Tools folder and run
> "setup.exe")

> Thanks.

> <%

> Dim oWShell, oFS, TempName, OutputText

> Set oWShell = CreateObject("WScript.Shell")
> TempName = "c:\test.txt"

> 'Here are the two commands to test:

> 'Test 1:

> 'Cmd = "cmd /c tlist -p excel.exe > " & TempName
> 'Result should be:
> '    -1    ---  if excel.exe is not running or
> '    640   ---  (or other correct PID) if running

> 'Test 2:

> Cmd = "cmd /c nbtstat -A > " & TempName
> 'Result should be:
> '         Local Area Connection: Node IpAddress: [123.456.789.012]
> Scope Id: []

> oWShell.Run Cmd, 0, True
> Set oFS = CreateObject("Scripting.FileSystemObject")
> OutputText = oFS.OpenTextFile(TempName, 1, True).ReadAll
> oFS.Close

> Set oFS = Nothing
> Set oWShell = Nothing

> Response.write("Output of call is: " & OutputText & "<br>")

> %>



Thu, 08 Jul 2004 01:03:11 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Piping results of command line call to file from ASP

2. Piping command results from DOS applications

3. Close or control any windows app from command line or batch file by calling WinAPI

4. How do you execute a command-line program, and return the results into a variable

5. use the result of the VBS for other application under the command line

6. Passing values into and out of Command Line application *and* command line prompt in vbscript

7. Scripting command line applications & Command Line Prompting

8. How to pipe command output to text file?

9. ASP commands produce no results in browser

10. Command Line call pstotext

11. Parameters in command line location calls

12. Calling an Executable from command line

 

 
Powered by phpBB® Forum Software