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
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  
 
 [ 2 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. Command-line compile, result throws error

10. Command Line Results

11. Capture text results from command line

12. ASP commands produce no results in browser

 

 
Powered by phpBB® Forum Software