in reply to running command line from Perl

your standard shell is most probably CMD but the command you are trying to run is Powershell.

> # this runs fine from command line

which is powershell? (look at the preceding PS)

> `` works perfectly fine on macOS

MacOS supports PS?

UPDATE

TIMTOWTDI, but this works for me

C:\tmp>perl print `powershell Invoke-Command -ScriptBlock {"get-wmiobject Win32_Co +mputerSystemProduct | select-object -ExpandProperty UUID"}` __END__ C44A693E-8B14-11EC-6464-A0542DA054C5

Only tangentially a Perl question, you need to find ways to execute your PS from CMD ...

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: running command line from Perl
by karlgoethebier (Abbot) on May 18, 2022 at 13:40 UTC
Re^2: running command line from Perl
by Anonymous Monk on May 18, 2022 at 12:11 UTC

    You are right. I am using Powershell but CMD is standard.

    I found this alternative for CMD:

    wmic path win32_computersystemproduct get uuid #works in CMD

    Still I do not get the principle from Perl for CMD

    my $UUID = system ('wmic path win32_computersystemproduct get uuid');

    No PS on macOS. I meant the way to call a command from Terminal works out-of-the-box. This works on macOS:

    my ($UUID) = `ioreg -d2 -c IOPlatformExpertDevice` =~ /^.*\bIOPlatform +UUID\b.*"([^"]+)"\s*$/m or print "failed to parse ioreg";
      > system ('wmic path win32_computersystemproduct get uuid');

      ehm ... works for me °,

      C:\tmp>perl print system ('wmic path win32_computersystemproduct get uuid'); __END__ UUID 2DA054C5-6464-11EC-8B14-A054C44A693E 0 C:\tmp>

      ... but you need to extract the second line from the output.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      update

      °) sorry, the demo is misleading, see Re^6: running command line from Perl

      a working approach is:

      C:\tmp>perl $a=qx(wmic path win32_computersystemproduct get uuid); print "<<<$a>>>"; __END__ <<<UUID 2DA054C5-6464-11EC-8B14-A054C44A693E >>> C:\tmp>

        system does not capture output, "print" in parent just says "0"

      Nothing stops you from using system to run powershell instead of cmd.

      Please look at my update for another way to do it :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Rolf, that update is super. Thank you!