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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |