1

次のようなbashスクリプトがあります:

# gets all relevant files in the directory
cp ../update_files/* ./transfer_dir

# copy the python scripts to that directory
cp ../tools/update_tool/* ./transfer_dir

# execute the python scripts 
python ./transfer_dir/merge.py

ここでの問題は、Python スクリプトを実行しようとすると、「作業ディレクトリ」が ./transfer_dir ではなく ./transfer_dir であることがわかり、以前にコピーした update_files をファイルできないことです。

どうすればそれを変更できますか? ほとんどの場所に依存しないため、Python スクリプトをあまり変更したくありません。

4

2 に答える 2

7

使用cd:

cd transfer_dir
# execute the python scripts 
python merge.py
# restore old directory
cd ..                         
于 2012-01-30T20:13:40.913 に答える
1
  1. bashスクリプトのパスを変更できます@see ubuntus answer change working dir via bash

  2. スクリプト自体で作業ディレクトリを変更できます

    OSのインポート

    os.chdir("transfer_dir")

ソリューション 1 を使用することをお勧めします。2 を追加しただけです。

于 2012-01-30T20:23:49.660 に答える