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

20
LINES

< > BotCompany Repo | #1016739 // backtickToReceiver - run external process and call function on output

JavaX fragment (include)

static File backtickToReceiver(S cmd, IVF1<S> outputReceiver) {
  ret backtickToReceiver(cmd, (O) outputReceiver);
}

// returns file with program output (STDOUT+STDERR)
static File backtickToReceiver(S cmd, O outputReceiver) {
  File outputFile = createTempFile(cmd, ".out");
  makeEmptyFile(outputFile); // unnecessary?
  TailFile tail = tailFile2(outputFile, 100, voidfunc(S s) {
    pcallF(outputReceiver, s)
  });
  
  // make a dependent child process that is exited when we exit
  //print("Running: " + cmd);
  pcall {
    backtickToFile(cmd, outputFile);
  }
  tail.stop();
  ret outputFile;
}

Author comment

Began life as a copy of #1009098

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1016739
Snippet name: backtickToReceiver - run external process and call function on output
Eternal ID of this version: #1016739/4
Text MD5: c6dbaf56a03258c02a7a47507c256e83
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-10-22 00:41:18
Source code size: 620 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 332 / 371
Version history: 3 change(s)
Referenced in: [show references]