http://qs321.pair.com?node_id=1226065


in reply to How to execute a linux system command with perl?

A cleaned up copy of what you posted:

#!/usr/bin/perl use strict; use warnings; my @cmd = ('/sbin/route'); push @cmd, 'add'; push @cmd, 'default'; push @cmd, 'gw', push @cmd, '172.16.0.200', push @cmd, 'dev'; push @cmd, 'enxb827eb95400d'; system(@cmd);

some lines end with commas when they should be semicolons:

#!/usr/bin/perl use strict; use warnings; my @cmd = ('/sbin/route'); push @cmd, 'add'; push @cmd, 'default'; push @cmd, 'gw'; push @cmd, '172.16.0.200'; push @cmd, 'dev'; push @cmd, 'enxb827eb95400d'; system(@cmd);

If in doubt, print what your variables contain. Tutorials->PerlMonks for the Absolute Beginner/Basic debugging checklist.

Replies are listed 'Best First'.
Re^2: How to execute a linux system command with perl?
by cavac (Parson) on Nov 20, 2018 at 12:46 UTC

    Also:

    my @cmd = qw[/sbin/route add default gw 172.16.0.200 dev enxb827eb9540 +0d];

    or

    my @cmd = split/\ +/, "/sbin/route add default gw 172.16.0.200 dev enx +b827eb95400d";

    perl -e 'use MIME::Base64; print decode_base64("4pmsIE5ldmVyIGdvbm5hIGdpdmUgeW91IHVwCiAgTmV2ZXIgZ29ubmEgbGV0IHlvdSBkb3duLi4uIOKZqwo=");'