Question

<?php 
    ini_set('max_execution_time', 864000);
    $seq = "D:/Ractip/Sequence.txt";
    $mir = "D:/Ractip/mirhominid.txt";
    $shandle = fopen($seq, 'r');
    $sdata = fread($shandle, filesize($seq));
    $mhandle = fopen($mir, 'r');
    $mdata = fread($mhandle, filesize($mir));
    $sexp = explode(">", $sdata);
    $mexp = explode(">", $mdata);
    $i = 1;
    $a = 1;
    $count = count($sexp);

    while($i < $count)
    {
        $name = explode("\n", $mexp[$a]);
        $name = explode(" ", $name[0]);
        $name1 = explode("\n", $sexp[$i]);

        $file2 = "D:\Ractip\mir\\"."$name[1]".".txt";
        $file1 = "D:\Ractip\sequence\\"."name1[0]".".txt";

        if ($i == 1){
            mkdir("D:/Ractip/Interactions/"."$name[1]", 0777);
        }

        $file = "D:/Ractip/Interactions/"."$name[1]"."/"."$name1[0]"."+"."$name[1]".".txt";
        $fhandle = fopen($file, 'w');
        $query = "ractip "."$file1"." "."$file2";

        $exec = shell_exec($query);
        print $exec;
        fwrite($fhandle, $exec);
        fclose($fhandle);
        if ($i == $count){
            $i = 1;
            $a++;
        }else{
            $i++;
        }
    }
?>

This is the script. I am basically using a tool to get results of roughly 37.5 million combinations, so as you can understand it isn't something I can do on my own, therefore came along this script, previously I separated all candidates into individual files and so that is the explanation for the $name variables I'm calling them that way.

The problem is the shell_exec command, a preliminary Google search really did not explain why it is behaving this way, but shell_exec refuses to process dynamic commands, instead if I were to make a static command like ractip xy.txt zy.txt it will process that, what I need to do is build the command and then make the shell_exec process it, which it unfortunately isn't doing, it would be really helpful if someone can explain why this command behaves this way and if there is a workaround to this glitch.

I've finally gotten around to understanding what a guy on a forum meant when he said that these are just some things php doesn't do very well.

Oh yes, and I am deploying it through the browser, dunno if that is any help.

Was it helpful?

Solution

On both Windows and Linux, you'll be better off by keeping all slashes like "/".

Also, looks like you forgot a $ in $file1:

$file2 = "D:/Ractip/mir/" . $name[1] . '.txt';
$file1 = "D:/Ractip/sequence/" . $name1[0] . ".txt";

Finally, just in case, for clarity, I'd write

$query = "ractip '$file1' '$file2'";

or

$query = 'ractip ' . $file1 . ' ' . $file2 ;

You don't really need to quote a single string variable, i.e. $string and "$string" are the same thing. I did quote $file1 and $file2 with single quotes /inside/ $query, because, if the names contain spaces, the ractip utility would get confused as to where one filename stops and another starts. Maybe it's not your case here, but anyway...

OTHER TIPS

What I observed in your code is that in the file names you are passing, the slashes are not properly escaped:

$file2 = "D:\\Ractip\\mir\\"."$name[1]".".txt";
$file1 = "D:\\Ractip\\sequence\\"."name1[0]".".txt";

This might be causing the command to search for a wrong file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top