Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a system call in dart?

Tags:

dart

I want to execute a python or a java class from inside dart.

The following is a snippet which I have used from a stackoverflow question Java

Runtime currentRuntime = Runtime.getRuntime();
Process executeProcess = currentRuntime.exec("cmd /c c:\\somepath\\pythonprogram.py");

I would like to know how to make such calls in dart.

Basically I have a UI where in the user uploads code in java and python.I want to execute the uploaded code from the dart environment instead of creating a routine in java or python on the folder where the code is uploaded.

I personally dont know if this is possible, since dart is purely in a VM.

I want to execute the following command

java abc

from inside dart.

like image 454
IBRIT Avatar asked Jan 15 '13 21:01

IBRIT


1 Answers

You can simply use Process.run.

import 'dart:io';

main() {
  Process.run('java', ['abd']);
}

You can also access to stdout, stderr and exitCode through the resulting ProcessResult :

import 'dart:io';

main() {
  Process.run('java', ['abd']).then((ProcessResult pr){
    print(pr.exitCode);
    print(pr.stdout);
    print(pr.stderr);
  });
}
like image 153
Alexandre Ardhuin Avatar answered Sep 28 '22 01:09

Alexandre Ardhuin