I want to execute some processes one by one in dart using either Process.run() or Process.start()
And I want to show the verbose log of the process. But the problem is Whenever I am using run it's providing the stdout in a string i.e., at the end of the process completion. But I want to display the logs while the process is being executed.
Cause run is returning us the instance of ProcessResult instead of Process, the returned stdout is String.
Have to use stdout.write(cleanProcess.stdout); in case of run;
OR
Now in case start(), I am getting stdout as Stream which is desired but the only problem is the start returns us to the Process and Doesn't actually await for the Process to complete.
Can use stdout.addStream(buildProcess.stdout); to display stdout as stream
Code that I am trying to execute, and display the verbose.
print("HighSupply Executor : flutter clean");
var cleanProcess = await Process.run('flutter', ["clean", "--verbose"],
workingDirectory: "${flutterFolder.path}");
stdout.write(cleanProcess.stdout); //only getting stdout in one go. needed as stream.
print("HighSupply Executor : flutter pub get");
var pubGetProcess = await Process.run('flutter', //OR can we use start and wait for process to complete
["pub", "get", "--verbose"],
workingDirectory: "${flutterFolder.path}");
stdout.write(pubGetProcess.stdout);
print("HighSupply Executor : flutter build apk");
var buildProcess = await Process.run(
'flutter', ["build", "apk", "--verbose", generatedParams],
workingDirectory: "${flutterFolder.path}");
stdout.write(buildProcess.stdout);
TL;DR
Can I anyhow get stdout as a stream in case Prcocess.run() OR Can we wait for Process to complete before executing another in case of Process.start()
Any help is appreciated.
Edit: 1
As @julemand101 suggested to use exitcode and wait for it to return after the process completion, It works fine with my case, and haven't run into any issue yet but As he mentioned and stated in docs that is not reliable, so we are looking for a better concrete solution for it.