Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

18
LINES

< > BotCompany Repo | #1009630 // windows_killAll - non-working version with wmic

JavaX fragment (include) [tags: archive]

static L<Int> windows_killAll(fS pattern) {
  if (!isWindows()) fail("No Windows");
  L<S> lines = lines(loadTextFile(backtickToConsole("WMIC path win32_process get ProcessId,CommandLine")));
  S head = first(lines);
  int iPID = indexOfIgnoreCase(head, "ProcessId");
  int iCommand = indexOf(head, "CommandLine");
  new L<Int> pids;
  for (S s : dropFirst(lines)) {
    S command = grabUntilSpace(s.substring(iCommand));
    if (cic(command, pattern)) {
      int pid = parseFirstInt(s.substring(iPID));
      pids.add(pid);
      print("Killing " + pid + ": " + command);
    }
  }
  windows_killProcesses(pids);
  ret pids;
}

Author comment

Began life as a copy of #1009616

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): cfunsshuasjs, mqqgnosmbjvj

No comments. add comment

-
Snippet ID: #1009630
Snippet name: windows_killAll - non-working version with wmic
Eternal ID of this version: #1009630/1
Text MD5: cbebc13dc8f8e509baf17d7fa2d78f40
Author: stefan
Category: javax / windows
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): Yes
Created/modified: 2017-08-12 19:09:54
Source code size: 645 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 445 / 452
Referenced in: