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)

1  
static File backtickToReceiver(S cmd, IVF1<S> outputReceiver) {
2  
  ret backtickToReceiver(cmd, (O) outputReceiver);
3  
}
4  
5  
// returns file with program output (STDOUT+STDERR)
6  
static File backtickToReceiver(S cmd, O outputReceiver) {
7  
  File outputFile = createTempFile(cmd, ".out");
8  
  makeEmptyFile(outputFile); // unnecessary?
9  
  TailFile tail = tailFile2(outputFile, 100, voidfunc(S s) {
10  
    pcallF(outputReceiver, s)
11  
  });
12  
  
13  
  // make a dependent child process that is exited when we exit
14  
  //print("Running: " + cmd);
15  
  pcall {
16  
    backtickToFile(cmd, outputFile);
17  
  }
18  
  tail.stop();
19  
  ret outputFile;
20  
}

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: 403 / 444
Version history: 3 change(s)
Referenced in: [show references]