in reply to Re: running command line from Perl
in thread running command line from Perl

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";

Replies are listed 'Best First'.
Re^3: running command line from Perl
by LanX (Saint) on May 18, 2022 at 12:41 UTC
    > 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"

        Documentation for system explicitly says:

        This is not what you want to use to capture the output from a command; for that you should use merely backticks or qx//, as described in "`STRING`" in perlop. Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason).

                        "These opinions are my own, though for a small fee they be yours too."

Re^3: running command line from Perl
by ikegami (Patriarch) on May 18, 2022 at 17:57 UTC

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

Re^3: running command line from Perl
by LanX (Saint) on May 18, 2022 at 12:12 UTC
    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!