저는 리눅스에 익숙하지 않고 작성하려고하는 PHP 스크립트에서 bash 명령을 사용하려고 시도하고 있습니다. 각 PDF를 작성해야합니다. PHP에서 DirectoryIterator()를 사용하여 다른 폴더에 앉아서 텍스트 파일의 새 줄에 각 파일 이름이 나열된 .lst 파일을 반복하는 디렉토리의 파일 이름입니다.bash 명령을 사용하여 .lst 파일에 파일 이름 목록을 쓰는 방법
.LST 파일은 다음과 같아야합니다
1.pdf
2.pdf
3.pdf
...
나는이 말이 바랍니다. 모든 도움/지시가 크게 감사 할 것입니다.
// Use the command line cp to copy each PDF file in the sourceDir to the destinationDir.
foreach ($srcDir as $entity) {
/**
* @var DirectoryIterator $entity
*/
/*$result = rename($sourceDir . '/' . $entity->getFilename(), $destinationDir .'/' . $entity->getFileName());
if(!$result)
{
throw Exception('Could not copy file ' . $entity->getFilename() . 'to destination directory ');
}*/
$cpString = 'cp ' . $sourceDir . '/' . $entity->getFilename() . ' ' . $destinationDir .'/' . $entity->getFileName() . ' 2<&1';
passthru($cpString, $returnVar);
if($entity->isFile() && strtoupper($entity->getExtension()) == 'PDF')
{
$cpString = 'cp ' . $sourceDir . '/' . $entity->getFilename() . ' ' . $destinationDir .'/' . $entity->getFileName();
if ($counter = 1) {
$catString = 'cat ' . $destinationDir . '/' . $batchNum . '.lst';
}
$cpString = ''
}
$counter++;
}
아래 grawity의 대답은 완벽해야 @ : 여기
내가 지금까지 가지고 올 한 코드입니다. bash 명령을 사용해야하는 이유가 있습니까? 파일을 어딘가에 복사하려고합니까? – terdon예. 상사가 PHP 코드 내에서 bash 라인 명령을 사용하기를 원한다. 왜냐하면 필자는 bash와 PHP 스크립트가 처음이기 때문에 더 익숙해 져있다. 희망은 그 말이 맞습니다. 감사. – Melinda
[이 답변] (http://superuser.com/a/474581/57398)에 설명 된'echo -n' 옵션과 같은 것이 도움이 될 수 있습니다. – martineau