How to run command with "*"
sunjianan9900 opened this issue · comments
can not run command :
du -sh *
du: *: No such file or directory
but i can run:
du -sh fileName
only i run du -sh "*" on my mac , i will got
du: *: No such file or directory
so , it seems like auto add " for *
ps: * not work
That's puzzling indeed. The arguments are correct when Process.start
is called so there is not much thing that can be done.
The alternative solution is to explicitly list the files (yes I know *
was very convenient here!) first with something like
var path = Directory.current.path;
// List files/folder in the given path first
var fileList = (await Directory(path).list().toList())
.map((e) => basename(e.path))
.toList();
// Call du will an explicit list instead of '*'
await Shell().run('du -sh ${shellArguments(fileList)}');
That's puzzling indeed. The arguments are correct when
Process.start
is called so there is not much thing that can be done.The alternative solution is to explicitly list the files (yes I know
*
was very convenient here!) first with something likevar path = Directory.current.path; // List files/folder in the given path first var fileList = (await Directory(path).list().toList()) .map((e) => basename(e.path)) .toList(); // Call du will an explicit list instead of '*' await Shell().run('du -sh ${shellArguments(fileList)}');
Thanks a lot !
another issue
'du -sh ${shellArguments(fileList)} | sort -rh '
|: No such file or directory
it seems like everything after -sh would be file
Shell specific command (pipe, stderr redirect...) are not supported
Each command must evaluate to one executable (i.e. no loop, pipe, redirection, bash/powershell specific features).
You can easily extract the resulting lines (outLines) and sort using dart (well...example below does not sort the way you want, it is just an example):
var lines = ((await Shell().run('du -sh ${shellArguments(fileList)}'))
.outLines
.toList())
// Sort it the way you want
..sort();
Shell specific command (pipe, stderr redirect...) are not supported
Each command must evaluate to one executable (i.e. no loop, pipe, redirection, bash/powershell specific features).
You can easily extract the resulting lines (outLines) and sort using dart (well...example below does not sort the way you want, it is just an example):
var lines = ((await Shell().run('du -sh ${shellArguments(fileList)}')) .outLines .toList()) // Sort it the way you want ..sort();
yes , i have sort it ...
so like means any other command can be ineffectiveness..
Since pipe is a bash specific command you could also do something like that (surprisingly this works!)
await Shell().run('bash -c "du -sh * | sort -rh"');
Great