Working with Powershell (or other terminal)
LeXuanKhanh opened this issue · comments
Hi, is this possile to run powershell or other terminal in shell ? , it's seem like shell we are using on Windows is command prompt and I want run powershell on it by using run powershell
or powershell.exe
, since command on powershell is more similar to default terminal on Mac OS or Linux so I don't have to switch case base on the OS
I try and it open powershell successfully but after that I can't run any command on it, the controller don't send any event after I run powershell
I have looked this issue #29 , he could use powershell to send OS notification on Windows debug mode but only push once on release mode
My code:
void test() async {
controller.stream.listen((event) {
print(event);
});
try {
await shell.run('powershell.exe');
await shell.run('pwd');
} on ShellException catch (e) {
// We might get a shell exception
log('error');
log(e.result.stderr);
}
}
Shell is not a command prompt nor a scripting language, it only allows calling native binaries like you do in a console. And yes there are differences between platforms. However commands don't maintain a state, i.e. the command pwd
in your example is not ran in the context of the previous powsershell.exe
.
One solution is to call powershell with a list of command, or a script:
// You can run a command
await shell.run('powershell -c "pwd"');
// You can run a power shell script
await shell.run('powershell script.ps1');