Open a directory and run a PHP action

Asked

Viewed 184 times

0

I am trying to change the current directory to another and thus manage to perform an action. The script below is working, but only in the root directory. I would like to open, for example the /temp run and then quit again.

$comando="verifica_licenca.exe -v -f licencas$cnpj.dat";

//Executa o comando para verificar licença e armazena na variavel $line

$licencas = exec(escapeshellcmd($comando), $output);

reset($output);

while (list(,$line) = each($output)){

//Grava resultado da execução da execução no banco de dados

$stmt = mysqli_prepare($conexao, "INSERT INTO licenca (cnpj,dados, data) VALUES(?,?,?)");

mysqli_stmt_bind_param($stmt, 'sss', $cnpj, $line, $data);

mysqli_stmt_execute($stmt);

}

Thanks for your help.

  • You want to run the file verifica_licenca.exe across multiple directories? If so, use the absolute path, for example: C:\\Users\\user\\path\\to\\verifica_licenca.exe -v -f ...

1 answer

0


There are two ways to change the directory to exec:

chdir

Using the function chdir

$comando="verifica_licenca.exe -v -f licencas$cnpj.dat";

$path="c:\caminho\para\verifica\licenca\";

chdir($path); 

//Executa o comando para verificar licença e armazena na variavel $line

$licencas = exec(escapeshellcmd($comando), $output);

cd command

You can include the cd at your command:

$comando="cd \caminho\para\verifica\licenca\; verifica_licenca.exe -v -f licencas$cnpj.dat";

//Executa o comando para verificar licença e armazena na variavel $line

$licencas = exec(escapeshellcmd($comando), $output);
  • Hi Ricardo, I managed to solve using chdir, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.