|
Post by xxgeek on Apr 3, 2021 22:56:05 GMT
I'm looking for information on how to use PID, ID or whatever it takes to kill a running process, known or unknown from JB code.
Thanks in advance.
I need to kill processes in some experiments I'm doing.
|
|
|
Post by B+ on Apr 3, 2021 23:57:18 GMT
Task Master (Windows) End Task, I put it on my toolbar just for JB programs. (might want to save file first, that works even when stuck.)
Use scan in loops to use trap close code ie exit with the upper right corner X of Screen.
|
|
|
Post by xxgeek on Apr 4, 2021 1:38:12 GMT
Task Master (Windows) End Task, I put it on my toolbar just for JB programs. (might want to save file first, that works even when stuck.) Use scan in loops to use trap close code ie exit with the upper right corner X of Screen. That's not what I'm asking B+ Thanks but I want to kill processes on the fly from a running bas file or the tkn or the exe.
|
|
|
Post by cundo on Apr 4, 2021 2:03:45 GMT
Maybe using an external tool. A task killer.
|
|
|
Post by xxgeek on Apr 4, 2021 2:09:36 GMT
Maybe using an external tool. A task killer. Thanks Cundo, I want to do it from JB code, but if it can't be done I'll most likely write a script in powershell or batch. btw - Cundo, I am adding your search engine for JB help to the program organizer with your name attached to it,unless of course you object. Oh, and it will be edited a little bit to fit with PO I'm working on quite few improvements and features so it'll be a while yet. Makes the last version seem amateur.
|
|
|
Post by B+ on Apr 4, 2021 3:04:11 GMT
How about throwing a Run Time error?
|
|
ntech
Junior Member
Posts: 99
|
Post by ntech on Apr 4, 2021 4:30:11 GMT
To kill a process by name, use
run "taskkill /IM process_name.exe"
by PID, use
run "taskkill /PID process_id"
Generally, though, there's no native way in JustBasic to find a PID of a program, and PIDs vary a lot, so there won't likely be a case where you know a program's PID. However, as seen above, it is possible to terminate a program just by its name.
|
|
|
Post by xxgeek on Apr 4, 2021 7:01:47 GMT
Thanks ntech, I'll do some experimenting with that.
I could have the user look it up and input the PID, but it's far faster execution if I can do it with code. Powershell or cmd could look it up, write it to a file, and then jb code could read the file, to taskkill it.
|
|
|
Post by B+ on Apr 4, 2021 20:56:08 GMT
Wouldn't you have to shut down JustBasic because JB is basically an interpreter running scripts, for .bas files at least.
|
|
|
Post by xxgeek on Apr 4, 2021 23:50:11 GMT
Wouldn't you have to shut down JustBasic because JB is basically an interpreter running scripts, for .bas files at least. B+, Most people I have known in my life live in what I refer to as a "steel box". That 'steel box' is created by their own minds due to influences, environment, experiences and of course the biggie "lack of knowledge" or "ignorance". Yet these people will force their opinions on others as "fact" (Don't get me wrong, I am not referring to you, or anyone else here for that matter) I just don't take advice as 'fact' from 'anyone'. I investigate, experiment, test, or whatever it takes to derive my own informed opinions, or facts. Re: My sig My "steel box" is more of a "soap bubble" I can walk through any time I feel the need. My motto is "There's always a way, you just have to find it" Now to your question. You are getting to close to what I am doing, and I want it under the rug until I "know for sure" I don't know that jbasic.exe needs to be shut down to run powershell scripts or batch files, haven't tried it yet (But I will find out.) When using RUN to open cmd, there is no problem. I see no problem arising by RUNing a batch script. Windows basically sees a bat file as a cmd command (or a bunch of commands) and will treat it about the same as it treats an EXE a PS1 a MSI and a few others like VBS, depending on installed support it will RUN python scripts etc etc. (Now I don't mean Windows treats them exactly the same, but you get my drift. They open, and they RUN, and that's all I need them to do. I may WANT to shut down jbasic.exe, but I would need to know I am shutting down the RIGHT "instance", or "childprocess" before I do it. I don't know yet if a script can get me the info I need, but I will do what I can to find out. I'm going to shut that bast (oops) down no matter what it takes. Thanks B+, you get me thinking every time we have interaction. I love it. Us crazy people need to think constantly, or we tend to lose our minds.... (again)
|
|
|
Post by Rod on Apr 5, 2021 9:17:46 GMT
|
|
|
Post by B+ on Apr 5, 2021 18:24:27 GMT
From JB program:
run "powershell taskmgr"
|
|
|
Post by xxgeek on Apr 22, 2021 1:01:00 GMT
To kill a process by name, use run "taskkill /IM process_name.exe"
by PID, use run "taskkill /PID process_id"
Generally, though, there's no native way in JustBasic to find a PID of a program, and PIDs vary a lot, so there won't likely be a case where you know a program's PID. However, as seen above, it is possible to terminate a program just by its name. The process I was trying to kill was jbasic.exe, but I wanted to kill a certain child process if I could, and it still may be possible with the help of cmd and or powershell. I haven't done enough research on it yet. taskkill /IM jbasic.exe won't work. It comes back with the "Do you want to save changes" window. You need to force it with the /F switch then there is no message, just a dead jbasic.exe or two or 3 or..... I did find some interesting commands that some of you guys might want to use. taskkill /IM jbasic.exe /F - kills ALL running jbasic.exe instances. Make a new file named killjb.bat with this line, and keep it handy for when JB processes hang and you usually would need to go to taskmanager to kill the process. It can be used in JB code as well, I've done it using - run "taskkill /IM jbasic.exe /F" . JB won't commit suicide using JB code, but it lets you call someone who will commit it's murder. Strange, but true. So when you get one of those "not responding" messages just click the bat file (maybe twice depending on your setup) Make sure you save any work you're doing in any instance of the JB editor, cause it kills everything that even looks like jbasic.exe. Even if it's had plastic surgery to hide it's identity. jk Gotta have some fun now and again with all the reading and programming and frustrations that come with it. taskkill /f /fi "status eq not responding" - this supposedly kills the "non responding" process" ONLY. Haven't had a non responder for while so I can't verify yet. Of course to use it in JB you need the right syntax and a bit of fancy footwork because of the 2 " characters, but you guys know how to deal with those. I tried this with the /fi in the first commandline above and it didn't work so if it doesn't work you, try it without the /fi I'm pretty sure a powershell script can find all process id's or PID's using names and switches like eq etc to kill 'precisely' whatever you want to. I just haven't had the time to go research it yet. But I did 'some' research and it is possible. Keep in mind that JB code can write batch and powershell scripts to files on the hard drive, then "RUN" them too. ntech - You were so close, but you didn't know it was jbasic.exe I was trying to kill. Thanks again for pointing the way. So, I believe we can kill a RUNING jbasic.exe using a a renamed jbrun2.exe(with a tkn) while the jbrun2.exe is still running to start or restart a bas file using run "jbasic -R, that starts a jbrun2.exe(tkn) that kills jbasic.exe and so on. I'm working on a few large projects right now, and don't have so much time to experiment with this, but decided to post what I have found for those who wish to have some real fun.
|
|