Computer Science Canada

Not exiting at eof

Author:  Thuged_Out_G [ Thu Aug 10, 2006 7:13 pm ]
Post subject:  Not exiting at eof

code:

proc listProcess
    if not Sys.Exec ("C:\\WINNT\\system32\\cmd /k tasklist /svc >> c:\\test.txt") then
        put Error.LastMsg
    end if
    var file : string := "C:\\test.txt"
    var fileNum : int
    var input : string
    open : fileNum, file, get
    loop
        exit when eof (fileNum)
        get : fileNum, input : *
        put input
    end loop
    close : fileNum
end listProcess


Can someone please explain why that loop isnt stopping at eof, it just continually reads the file, over and over.

Author:  Thuged_Out_G [ Thu Aug 10, 2006 9:16 pm ]
Post subject: 

Ok, got the loop issue figured out ... another problem arrises, which im unsure as to the best way to deal with.

code:

var win := Window.Open ("title:win")
var file : string := "C:\\test1.txt"
var fileNum : int
var input : string
var inputChar : string
var sys : int
var ch := '"q"'
View.Set ("text")


proc getProcess
    open : fileNum, file, write
    close : fileNum
    if not Sys.Exec ("C:\\WINNT\\system32\\cmd.exe /k tasklist /svc >> C:\\test1.txt") then
        put Error.LastMsg
    end if
end getProcess

proc listProcess
    delay (5000)
    open : fileNum, file, get
    loop
        exit when eof (fileNum)
        get : fileNum, input : *
        put input
    end loop
    close : fileNum
end listProcess

proc killProcess
    var PID : string
    put "Enter the PID of the process you would like to end: " ..
    get PID
    if not Sys.Exec ("C:\\WINNT\\system32\\cmd.exe /k ntsd -p " + PID + " -c " + ch) then
        put Error.LastMsg
    end if
end killProcess

getProcess
listProcess
killProcess


That is my code, my problem is after listProcess is called, im left with a command prompt, the same issue after I kill a process.
Does anyone know of a way I could close each command prompt after the the command is executed.

Author:  NikG [ Thu Aug 10, 2006 10:25 pm ]
Post subject: 

Thuged_Out_G wrote:
if not Sys.Exec ("C:\\WINNT\\system32\\cmd.exe /k tasklist /svc >> C:\\test1.txt") then
...
Use the /c parameter instead of the /k. That should terminate the window after it's done doing what it supposed to.
(Just a note, I found that by typing in "help cmd" into the command prompt.)

Author:  Thuged_Out_G [ Fri Aug 11, 2006 7:19 am ]
Post subject: 

code:

if not Sys.Exec ("C:\\WINNT\\system32\\cmd.exe /k tasklist /svc >> C:\\test1.txt&&exit")


Is what I found, i'll try the /c those when I get home .. thanks!
Also, I was told on a website article that using the above ntsd command I could kill any process, Although try to kill certain processes always comes back with a access denied message.


: