Shell errors running php exec

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Mar 26, 2018 11:37 am

Fri Jul 27, 2018 10:10 am

I have a php script that executes a shell command to find the common items between two files given. This is the beginning of my php script:

Code: Select all

    $E7Bonded_File = "/opt/IBM/custom/NAC_Dslam/junk/PortParameter_E7_Bonded_cust_stats.csv";
    $E7Single_File = "/opt/IBM/custom/NAC_Dslam/junk/PortParameter_E7_Single_cust_stats.csv";
    $E7Common_File = "/opt/IBM/custom/NAC_Dslam/junk/Common_tn_SingleBonded_E7_cust_stats.csv";
    //This will be a list to add to the existing Common file to use to post-process the files.
    exec ("comm -12 <(cut -d ',' -f2 $E7Single_File| sort) <(cut -d ',' -f2 $E7Bonded_File| sort)", $outputCommon); 
I see this error message when I run the script:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `comm -12 <(cut -d ',' -f2 /opt/IBM/custom/NAC_Dslam/junk/PortParameter_E7_Single_cust_stats.csv| sort) <(cut -d ',' -f2 /opt/IBM/custom/NAC_Dslam/junk/PortParameter_E7_Bonded_cust_stats.csv| sort)'
I checked, and the parenthesis look ok for my exec line.

When I run the shell command at the command line it returns a listing of numbers like I expect:

Code: Select all

     comm -12 <(cut -d ',' -f2 junk/PortParameter_E7_Single_cust_stats.csv| sort) <(cut -d ',' -f2 junk/PortParameter_E7_Bonded_cust_stats.csv| sort)

I looked online and I seem to be using exec correctly. I want the numbers returned to be stored as an array, $outputCommon.

I did "which sh" at the command line and it returned
I added this line to my script,
exec("which sh",$throwaway); var_dump($throwaway);
and it returned /bin/sh as well. I've used pipes in commands I execute in php exec before.

Any ideas about this error message?

Post Reply