2012-04-19 43 views
0
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"); 

這個PL文件工作正常的Windows而不是Linux上,因爲回聲Linux是不接受的文本之間的空格!我如何解決它perl的重定向的Linux

+0

其顯示在linux空文件 – 2012-04-19 06:08:46

+0

您需要添加單或雙引號這樣的系統(「回聲\」 $ device_create_cmd \「> command.txt」); – 2012-04-19 06:18:58

+0

但這不會在窗戶上工作,然後它會產生額外的引號...... – 2012-04-19 06:20:20

回答

4

只需打開該文件,並寫入到它你自己。爲什麼要涉及殼?

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" 
    } … 
+0

它應該工作!我會試試!! Thnks – 2012-04-19 06:42:48