
私は、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 サーバーで実行しているときはこのエラーは表示されません。Ubuntu for Windows で実行しているときのみ表示されます。エラーで、ディレクトリ パスがコピーされていることに気づきました: 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]
これを行うにはもっと良い方法がありますので、後で回答を修正し(質問の形式を変更し)、再度試してみます。