Sree Ram
Sree Ram

Reputation: 859

perl redirection linux

sub cdevice{
    $p=$_[0];
    $s=$_[1];
    $q=$_[2];
    try {
        $device_create_cmd ="create type:NSR Device;media type:adv_file;name:$p;device access information:$p";
        system("echo $device_create_cmd > command.txt  ");
    } catch Error with {
        print "Error  " ;
        exit();     
    };
}
cdevice("/device1","raddh054","/device1");

this pl file is working fine on Windows but not on Linux because echo in Linux is not accepting spaces between the text !how do i resolve it

Upvotes: 0

Views: 100

Answers (1)

daxim
daxim

Reputation: 39158

Simply open the file and write into it yourself. Why involve the shell at all?

use strictures;
use autodie qw(:all);

⋮

sub cdevice {
    my ($p, $s, $q) = @_;
    try {
        open my $h, '>', 'command.txt';
        print {$h} "create type:NSR Device;media type:adv_file;name:$p;device access information:$p\n"
    } …

Upvotes: 4

Related Questions