Hello,

I try to execute a command on Windows by sending that command from Linux. I did it in bash code as test but when I tried it in perl, I could not achieve what I wanted. What can I not see in these codes, can you help me ?

(Update#1 win2 of bash code)

(Update#2 with newline (\n), I solved the mistery, )

bash code;

#!/bin/bash # to test it continuosly I keep 1copy.txt untouched # there are 4 lines in it, the first line is # ac wavSound\test.wav adpSound\test01.adp -norm cat 1copy.txt > 1.txt i=`wc -l 1.txt | awk '{print $1}'` # get line count while [[ $i -gt 0 ]] do (( i-- )) head -n1 1.txt > bat.bat # get first line into bat file sed 1d 1.txt > 2.txt # remove first line and save it new file mv 2.txt 1.txt # move it back to original file #put bat file onto Windows machine sftp adp@10.10.110.222 <<EOF put bat.bat EOF #execute bat file in cmd ( win2 has one line; start "" "bat.bat" )#Upd +ate #1 ssh adp@10.10.110.222 cmd.exe < win2 sleep 12 #without this sleep,it ends so fast, it can only #produce one adp file randomly, sometimes its test01.adp #sometimes its test04.adp done

perl code;

sub winUse { my $wavF =shift; my $adpC =shift; # Channel info my $adpT =shift; # Title info my $adpF = "channel$adpC-title$adpT.adp"; my $batF = "adp2.bat"; #bat file my $ordF = "cmdWin"; #windows command to exec my $wavD = "wavSound"; #wav dir my $adpD = "adpSound"; #adp dir my $winS = "10.10.110.222"; #win server my $winU = "adp"; #win user my $fh; # FileHandle my @cnvrtArray = ( "ac"," ", #adpcm_converter.exe $wavD,"\\", #wav directory on windows $wavF," ", #wav source file $adpD,"\\", #adp directory on windows $adpF," ", #adp goal file "-norm" #parameters ); open($fh,'>',$batF) or die "Can't write file '$batF' [$!]\n"; print $fh @cnvrtArray; close($fh); open($fh,'>',$ordF) or die "Can't write file '$ordF' [$!]\n"; #print $fh $batF; # First post print $fh 'start "" "'.$batF.'"'."\n"; # Update #2 close($fh); my $sftpString1 = "sftp $winU\@$winS<<EOF\nput $batF\ncd $wavD +\nput $wavF\nEOF"; my $sshString = "ssh $winU\@$winS cmd.exe < $ordF\n"; my $sftpString2 = "sftp $winU\@$winS<<EOF\ncd $wavD\nrm $wavF\ +ncd ..\/$adpD\nget $adpF\nEOF"; system($sftpString1); sleep 5; system($sshString); sleep 10; system($sftpString2); sleep 5; } winUse("test.wav",52,24); winUse("test.wav",52,25); winUse("test.wav",52,26);

In reply to Bash vs Perl. Why doesn't work...? by ali_kerem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.