Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's generally quite doable to write functions for that, e.g. in perl -

  use IPC::System::Simple qw(capture);
  use Sub::Install qw(install_sub);
  
  foreach my $command (qw(foo bar baz)) {
    install_sub $command => sub { capture($command, @_) }
  }
  
  ...
  
  my $output = foo($x, $y); # will throw if calling 'foo $x $y' returns non-zero
(there's a Shell.pm but it's not as helpful with errors; I should probably consider rewriting it a more modern way)

Note that if you're distributing code p3rl.org/App::FatPacker will produce a single fat script that has (pure perl) dependencies included so you don't need to install anything (except for having a perl VM in $PATH).

There's also multiple libraries that provide a '$' function in JS (which may be why amber picked that delimeter) and then you can do

  let output = await $`foo ${x} ${y}`;
(the template string's variable parts get autoquoted)

Note that bun.sh has a 'bun compile' subcommand that bolts together your (pure JS) code and the static bun binary to produce a single file you can also copy around.

I'd suggest avoiding backticks in ... everything. In shell, $() is nicer, and both perl's and ruby's backticks require effort to use safely.

No idea re python but I see no reason you couldn't do the function generation thing if you wanted to, and somebody's probably librarified it already.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: