tekartik / process_run.dart

Process run helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flutter console reports a crash even with some successful commands

merrycachemiss opened this issue · comments

Hello

On Windows at least, if I do a command such as "ipconfig /?" to list the available commands, the flutter console will report a crash, even though the full output is returned to the console when I compare it to running it in cmd.exe proper.

(full output of "ipconfig /?" here)
flutter: ShellException(ipconfig /?, exitCode 1, workingDirectory: [directory])

The same thing happens when I run a few other commands that return output with lots of long text such as this. But weirdly, it doesn't always happen, and some commands that produce even longer text won't cause a crash. Maybe it's not related to the text amount, but certain characters in the text.

There are a few commands I want to run that will change the UI for the user, based on items in the text returned. If the commands runs successfully but there's still a crash, it doesn't return the output data, it only logs the output to the flutter console. Even if I could grab the flutter console text, I won't want such logs running in production.

As an aside, there should be a way to return the output as normal for commands that don't succeed, just associate a failure flag with it. If I put in a nonsense command like "developer" in, this is what happens:

developer
'developer' is not recognized as an internal or external command, operable program or batch file.
flutter: ShellException(developer, exitCode 1, workingDirectory: [directory])

If I have a text input for the user, they should know of the error text "'developer' is not recognized as an internal or external command, operable program or batch file." that's being produced, but the crash makes the text inaccessible as far as I know.

I've read on here in other issues that you don't use Windows, so for now I've attached the output of crash vs no crash commands from cmd.exe, maybe there's a pattern in what these produce. I can't find one for sure -- hopefully other users can take a peek and compare them, too.

Could it relate to the output in the crash ones having ">" or "$" in the text?

The "chkdsk /?" had a different exit code of 3, but maybe because this is associated with the requirement of normally needing to run cmd as admin to do anything with chkdsk, even though the help flag produces an output in non-admin mode. Including it anyway.

Thank you in advance. Other than this quirk, I'm having a blast using this. I don't think my project could have even been started so soon, without it.

nocrash_schtasks_help.txt
nocrash_tasklist_help.txt
crash_chkdsk_help_exitcode_3.txt
crash_ipconfig_help_exitcode_1.txt
crash_prompt_help_exitcode_1.txt
nocrash_driverquery_help.txt
nocrash_format_help.txt
nocrash_powercfg_help.txt

I think some help commands returns non 0 when displaying help so maybe you should ignore that. It is not clear in the documentation how to ignore error:

By default, run will throw an error if the exitCode is not 0. You can prevent that
with the option throwOnError which is true by default:

void main(List<String> arguments) async {
  // Prevent error to be thrown if exitCode is not 0
  var shell = Shell(throwOnError: false);
  // This won't throw
  await shell.run('dir dummy_folder');

  shell = Shell();
  // This throws an error!
  await shell.run('dir dummy_folder');
}

I think some help commands returns non 0 when displaying help so maybe you should ignore that. It is not clear in the documentation how to ignore error:

By default, run will throw an error if the exitCode is not 0. You can prevent that with the option throwOnError which is true by default:

void main(List<String> arguments) async {
  // Prevent error to be thrown if exitCode is not 0
  var shell = Shell(throwOnError: false);
  // This won't throw
  await shell.run('dir dummy_folder');

  shell = Shell();
  // This throws an error!
  await shell.run('dir dummy_folder');
}

Nice, I missed this trick, it fixed the problem 👍