dartssh2 icon indicating copy to clipboard operation
dartssh2 copied to clipboard

adding streams only suitable if shell is available

Open bradmartin333 opened this issue 11 months ago • 0 comments

how

i incorporated this from the docs

final shell = await client.shell();
stdout.addStream(shell.stdout); // listening for stdout
stderr.addStream(shell.stderr); // listening for stderr
stdin.cast<Uint8List>().listen(shell.write); // writing to stdin

await shell.done; // wait for shell to exit
client.close();

what

  1. run app from CLI -> no problems
  2. run app via double clicking on .exe -> FileSystemException: Error retrieving socket type, path = " (OS Error: The handle is invalid., errno = 6)

solution

import 'package:flutter/foundation.dart';
final shell = await client.shell();
if (kDebugMode) {
  stdout.addStream(shell.stdout); // listening for stdout
  stderr.addStream(shell.stderr); // listening for stderr
  stdin.cast<Uint8List>().listen(shell.write); // writing to stdin
}

await shell.done; // wait for shell to exit
client.close();

this works because I know the end users will only be running a release version, but I would like to know if there is a better way to prevent the error

bradmartin333 avatar Feb 13 '25 23:02 bradmartin333