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

46
LINES

< > BotCompany Repo | #1016732 // Backtick - run system command [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 107K of libraries. Click here for Pure Java version (15646L/112K).

1  
!7
2  
3  
sclass Backtick extends DynPrintLog {
4  
  S cmd;
5  
  S method = "Stefan's method";
6  
  transient JButton btnGo;
7  
  
8  
  JComponent visualize() {
9  
    ret northAndCenter(
10  
      vstackWithSpacing(
11  
        centerAndEastWithMargins(
12  
          withLabel("Command:", onEnter(jLiveValueTextField_bothWays(dm_fieldLiveValue('cmd)), r go)),
13  
            btnGo = jbutton("Go", r go)),
14  
        withRightMargin(jrightAlignedLine(withLabel("Method:", jLiveValueComboBox(ll("Stefan's method", "Apache Commons Exec"), dm_fieldLiveValue('method)))))),
15  
      super.visualize());
16  
  }
17  
  
18  
  void go() {
19  
    pcall-short {
20  
      temp enter();
21  
      temp tempDisableButton(btnGo);
22  
      clearPrintLog();
23  
      S cmd = this.cmd;
24  
      print("Running command with " + method + ": " + cmd + "\n");
25  
      
26  
      int exitValue;
27  
      if (eq(method, "Apache Commons Exec")) {
28  
        OutputStream stream1 = printOutputStreamWithIndent("  ");
29  
        OutputStream stream2 = printOutputStreamWithIndent("  ");
30  
        
31  
        exitValue = apacheCommonsExec_backtickToStreams(cmd, stream1, stream2);
32  
          
33  
        // print empty lines & flush stdout & stderr
34  
        stream1.write(toUtf8("\n"));
35  
        stream2.write(toUtf8("\n"));
36  
      } else {
37  
        LineBuffer buf = lineBuffer_printWithIndent("  ");
38  
        backtickToReceiver(cmd, vfAppendToLineBuffer(buf));
39  
        exitValue = backtick_exitValue;
40  
        print();
41  
      }
42  
        
43  
      print("Exit value: " + exitValue);
44  
    }
45  
  }
46  
}

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: #1016732
Snippet name: Backtick - run system command [Dyn Module]
Eternal ID of this version: #1016732/12
Text MD5: ae02b80452bd2cbb9b361c52b4acebb1
Transpilation MD5: 462e599f22cd07a35363343c283072e2
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-30 17:15:23
Source code size: 1504 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 392 / 651
Version history: 11 change(s)
Referenced in: [show references]