Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run shell script inside Angular app packaged in Electron

I have Angular 2 app packaged in Electron. I wonder if it is possible to run shell script from that app.

Thanks for any help.

like image 626
Tomas Marik Avatar asked Jul 17 '26 16:07

Tomas Marik


1 Answers

I was able to achieve that using ngx-childprocess

In 3 steps:

  1. in your electron/angular app install ngx-childprocess

    yarn add ngx-childprocess
    or
    npm install ngx-childprocess --save
    
  2. add gx-childprocess into app.module

    imports: [
        NgxChildProcessModulem
        ....
    
  3. run the script (in this case I am running java jar)

    import { ChildProcessService } from 'ngx-childprocess';
    ... 
    export class AppComponent {
    
       constructor(private childProcessService: ChildProcessService) {
            console.log('isElectronApp ' + childProcessService.isElectronApp);
            let options: string[] = [];
            childProcessService.childProcess.exec('java -jar child-process-test-1.0.jar', 
                                                  options,
                                                  (data) => {console.log(data);});
       }
    }
    
like image 159
Tomas Marik Avatar answered Jul 19 '26 05:07

Tomas Marik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!