anas
anas

Reputation: 13

Exec command returns 127 error code

To maket simple, i have a linux script that call a php script with only a zip command :

My bash file :

#!/bin/bash
  php zip.php 

My PHP file zip.php :

<?php
exec("zip file.zip file_1.pdf file_2.pdf file_n.pdf",$aOut,$errorCode);

This is what i get :

I see that its not the command not found error beacause it runs well with a small number of pdf files but its something related to the length of the 2en parameter or the entire command.

Someone can help please.

Upvotes: 1

Views: 7811

Answers (4)

soger
soger

Reputation: 1237

The problem is that the maximum length of a command line is 65535 bytes. I don't know why your command line test worked, maybe you've tried it with short filenames but one full command cannot exceed this limit.

The reason I found your question is because I was calling a command line with a heredoc as standard input, and well, the length of a heredoc can easily run away so I rewrote the call using popen() but that doesn't help you. I haven't worked with the zip utility yet, but a quick look at it's manpage says it appends files to existing archives so you should be able to split your command lines after every 64k if you want max efficiency, or after every 100 or even every single file if you want a simple algorithm.

Upvotes: 1

Vineet1982
Vineet1982

Reputation: 7918

Error Code 127:

127 means "command not found"

or

apache user has no permission to execute the command

Solution

The solution is to make sure that the command your are using can be found within your $PATH. If the command is not in your path either include it or use absolute full path to it.

or

Give apache user permission to execute command

Upvotes: 2

user9528614
user9528614

Reputation:

Hi Friend, It seems the PHP is not getting the file path or file doesn't have permission.

Upvotes: 0

JoinCompany
JoinCompany

Reputation: 514

try this:

<?php
exec("zip file.zip file_1.pdf file_2.pdf file_n.pdf >/dev/null 2>&1 &",$aOut,$errorCode);

>/dev/null 2>&1 & will run this command in background. and php just send command to linux

Upvotes: 0

Related Questions