News for hackers. Stuff that matters.
Re:The Dawn of a new Command Line Interface (2017) by rkangel on Tuesday April 13, 2021 @06:54AM (#26790534)
It is worth noting that this article is from 2017.
Re:The Dawn of a new Command Line Interface (2017) by p_l on Tuesday April 13, 2021 @07:14AM (#26790683)
Which is over 5 years after Powershell became common.
Re:The Dawn of a new Command Line Interface (2017) by INTPenis on Tuesday April 13, 2021 @07:25AM (#26790768)
Yes but some would argue Psh didn't become useful until release 6 in 2018.
Re:The Dawn of a new Command Line Interface (2017) by indymike on Tuesday April 13, 2021 @09:02AM (#26791591)
As long as I have to write C# wrappers to launch commands like I would in unix with xargs or parallel in PowerShell it's still not the ticket.
Re:The Dawn of a new Command Line Interface (2017) by p_l on Tuesday April 13, 2021 @09:53AM (#26792128)
And neither of those are native parts of shells but external applications, dare I say, just like the C# wrappers. (Especially parallel, since it's nowhere close to default install, and has very pesky license notice).

OTOH, PS 7.0 added ForEach -Parallel

Re:The Dawn of a new Command Line Interface (2017) by indymike on Tuesday April 13, 2021 @06:20PM (#26800116)
Yeah, but & is a thing and will do the job nicely as long as you don't try to pipe output to the same file... also, you can invoke pretty much any command with xargs... the issue was escaping escaped stuff with PowerShell. Hopefully things have gotten better.
Re:The Dawn of a new Command Line Interface (2017) by TeMPOraL on Tuesday April 13, 2021 @09:33AM (#26791897)
You shouldn't need to, unless your PowerShell installation doesn't support Invoke-Command, or ForEach-Object -Parallel...
Re:The Dawn of a new Command Line Interface (2017) by indymike on Tuesday April 13, 2021 @04:07PM (#26798438)
Yeah... shouldn't need to but... there are issues with escaping command line parameters with invoke-command and ForEach-Object that prevent parallelizing older cmd-style command line applications. The work around is to write a wrapper in a compiled language and use PowerShell to invoke the wrapper... There's a lot of really cool stuff in PowerShell.
Re:The Dawn of a new Command Line Interface (2017) by TeMPOraL on Tuesday April 13, 2021 @05:40PM (#26799697)
> there are issues with escaping command line parameters with invoke-command and ForEach-Object that prevent parallelizing older cmd-style command line applications.

Can you tell me more? So I know what to expect when I hit such issue myself.

> The work around is to write a wrapper in a compiled language and use PowerShell to invoke the wrapper...

Wonder if you need to really break out of PowerShell for this.

Recently when doing some scripting at work, I ended up writing .NET code straight in the script. It looks like this:

  $someCSharp = @"
  using System;
  //...
  public class Foo : Bar {
     public override object Baz(Quux arg) {
       //...
     }
  }
  "@
  
  Add-Type $someCSharp -ReferencedAssemblies C:\Path\To\Some\dependency-I-need.dll
This makes PowerShell compile your code into an in-memory assembly and make it available in the session, just as if it was an external .NET type. You could probably make a module out of it. Hell, cmdlets are .NET types underneath, you can make new ones from C#, so you could probably make such ad-hoc .NET classes available as PowerShell cmdlets.

I suppose using a proper .NET development environment for this would be more kosher; I arrived at the solution described above because my needs were simple, like binding .NET regex engine to SQLite (to get REGEXP operator in queries), or convincing Invoke-RestMethod to stop checking certificate validity.

Still, I love the capability, the fact that I can just drop into C# in the middle of the script. It's one of those things that make me think of Lisp machines and Common Lisp the experience of being able to deeply interact with your environment, and the joy of writing "scripts" that are automatically AOT-compiled (like with SBCL implementation of Common Lisp).

Re:The Dawn of a new Command Line Interface (2017) by p_l on Tuesday April 13, 2021 @07:45AM (#26790908)
That would be... an opinion. Not very grounded one unless one's whole base for it was "I couldn't use it on Linux".