'How to execute the command in another bash prompt in Perl?
I am working on CnvPytor and trying to automate some commands using Perl. But it is not working because when I give first command it is going inside another bash prompt (cnvpytor). Please refer the below screenshot,
I have written the below script, but it is not working
$x = `cnvpytor -root s1.pytor -view 10000`; #normal bash
$x = `set Q0_range -1 0.5`; # this and after this, enter into the cnvpytor
$x = `set p_range 0 0.0001`;
$x = `set p_N 0 0.5`;
$x = `set print_filename s1_output.vcf`;
$x = `set annotate`;
$x = `print calls`;
$x = `quit`;
Solution 1:[1]
There's no need for a temporary file, and you can still do it using backticks if you don't mind it using a shell. This also will allow you to capture the output of the cnvpytor command, if there is any. Here's how I would do it:
my $output = `cnvpytor -root s1.pytor -view 10000 2>&1 <<EOT
set Q0_range -1 0.5
set p_range 0 0.0001
set p_N 0 0.5
set print_filename s1_output.vcf
set annotate
print calls
quit
EOT`;
The 2>&1 redirects STDERR to STDOUT, which will cause it to be captured in $output. I feel that's usually a good idea whenever using backticks.
Solution 2:[2]
Each backtick pair runs a separate process.
I have no idea what CnvPytor is (and the link you provided doesn't help much), but the usual way is to run the external tool using some kind of IPC to communicate with it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ed Sabol |
| Solution 2 | choroba |

