
child_process를 사용하여 스크립트를 시작하는 노드 프로젝트가 있습니다. 스크립트는 파일을 반복하여 이미지로 변환하고 각 파일에 대한 경로를 배열에 저장하고 배열을 노드에 반환합니다. 그런 다음 그것을 읽기 위해 문자열로 변환하고 결과를 보기 위해 console.log를 수행합니다. 그러나 오류가 발생합니다.
I/O Error: Couldn't open file `'/mnt/c/localBarcodereader/pdf/calBarcodereader/pdf/[email protected]': No such file or directory.
mv: cannot stat '/mnt/c/localBarcodereader/pdf/calBarcodereader/pdf/[email protected]': No such file or directory`
Linux 서버에서 실행할 때는 이 오류가 표시되지 않습니다. Windows용 Ubuntu에서 이것을 실행할 때만 가능합니다. 디렉토리 경로가 복사되는 오류를 발견했습니다: calBarcodereader/pdf
여기 내 스크립트가 있습니다:
#! /bin/bash
날짜 +%F_%T
ndate=
OIFS=$IFS; IFS=$'\n'; array=($(find /mnt/c/localBarcodereader/pdf -type f - size +0b)); IFS=$OIFS for item in "${array[@]}" do
file=$item
file="${file:9}"
fname="${file::-4}"
PATHTOIMG= "/mnt/c/localBarcodereader/pdfimage/${fname}_${ndate}"
if [ ${file: -4} == ".pdf" ]; then
# pdftoppm /mnt/c/localBarcodereader/pdf/[email protected] /mnt/c/localBarcodereader/pdfimage/test -png -f 1 -singlefile -rx 1500 -ry 1500
pdftoppm /mnt/c/localBarcodereader/pdf/$file $PATHTOIMG -png -f 1 -singlefile -rx 1500 -ry 1500
mv /mnt/c/localBarcodereader/pdf/$file /mnt/c/localBarcodereader/pdfarchive
echo $PATHTOIMG
else
mv /mnt/c/localBarcodereader/pdf/$file /mnt/c/localBarcodereader/pdfarchive
fi done
내 노드 코드는 다음과 같습니다.
const cp = require('child_process')
try {
const data = cp.execSync('/mnt/c/localBarcodereader/barcodeScript.sh');
if (data.toString() !== "") {
console.log(data.toString())
답변1
스크립트가 Linux 서버에서 실행 중일 때 경로 이름이 훨씬 더 짧아진 것 같습니다.
빠른 수정으로 다음 줄을 변경하십시오.
file="${file:9}"
이에:
file="${file:30}"
본질적으로 변수를 다음과 같이 변경했습니다 file
.
/mnt/c/localBarcodereader/pdf/[email protected]
에게:
calBarcodereader/pdf/[email protected]
의도가 다음 file
과 같이 변경되는 경우:
[email protected]
이를 수행하는 더 좋은 방법이 있으며 잠시 후에 답변을 수정하고 질문의 형식을 다시 지정해 보겠습니다.