2016-09-28 9 views
0

私はそれは、コンソールでバッシュからproccessを印刷し、Bashのファイルを取り、それを実行し、このコードを持っている:実行後スクリプトとJava:出力ファイルを新しいフォルダに入れるにはどうすればよいですか?

package main.java.com.reachforce.java; 

import java.io.IOException; 
import java.io.InputStream; 

public class RunScript { 

    public static void main(String[] args) throws InterruptedException { 
     try { 
      // Run the process 

      Runtime run = Runtime.getRuntime(); 
      Process p = run.exec("C:/cygwin64/bin/bash -c \\'/bin/tests/SatoriTest1.sh 04.10 C:\\cygwin64\\bin\\tests"); 
      p.waitFor(); 

      // Get the input stream 
      InputStream is = p.getInputStream(); 

      // Read script execution results 
      int i = 0; 
      StringBuffer sb = new StringBuffer(); 
      while ((i = is.read()) != -1) 
       sb.append((char)i); 

      System.out.println(sb.toString()); 

     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

    } 
} 

、コンソール、それは私を示しています

テスト

は今すぐ実行

inputfile解説/入力プログラムファイルのフォーマット/ SatoriTest1出力に出力を書き込みSatoriTest1カール-k -v -i -X POST -d --output/SatoriTest1、出力 "のContent-Type:アプリケーション/ JSON" --header:私はどこにこれを理解しようとしていた

/さとりサービス/検証

エンドSatoriTest1.sh -H "アプリケーション/ JSONを受け入れます" "SatoriTest1-output"が作成されましたが...見つけられません。

これは.SHファイルです:

#!/bin/bash 
# 

# First need to compute directory for sourcing additonal files 
DIR="$(dirname "${BASH_SOURCE}")/.." 
CURLDIR=`dirname "$(readlink -f "$BASH_SOURCE")"` 
SCRIPTNAME="SatoriTest1" 

# This script relies on the getconfig settings so calling now . 
"${CURLDIR}/getmicroserviceconfig.sh" 

# Calling the getmicroserviceconfig.sh function to get the configuration 
getmicroserviceconfig 

# Also the formatSatori.sh FORMATFILE="${OUTPATH}/formatSatori.sh" 
if [ -f "${FORMATFILE}" ] then 
     . "${FORMATFILE}" 
fi 

# 
# Usage ./SatoriTest1.sh 
# 
# Testing /satori-service: POSTs a new address for validation 
# 
# Note: using -k to avoid certificate foof 
# 
# Depends on: 001-login test (to get a successful login w/security token) 

# SatoriTest1: /satori-service/validate: Satori address validation test 
#Expect this to submit an address to Satori address validation service 
# 

THISTEST="SatoriTest1.sh" 

APIPATH="satori-service/validate" FULLURL="${WEBSERVICEURL}/${APIPATH}" OUTPUTFILENAME="${OUTPATH}/SatoriTest1-output" 

echo "Test $SCRIPTNAME writing output to ${OUTPUTFILENAME}" 

NEWSATORIFILE="${OUTPATH}/inputfile" 

echo "Now formatting imput file ${NEWSATORIFILE}" 

formatSatori "${NEWSATORIFILE}" 

NEWSATORIREQ=$newsatorireq 

echo ${NEWSATORIREQ} > "${OUTPATH}/${OUTPUTFILENAME}.json" 

# 
# Now make the API calls using curl 
# 


# Calling POST with inputfile 
echo "Executing curl -k -v -i -X POST -d ${NEWSATORIREQ} --output ${OUTPUTFILENAME} --header \"Content-Type: application/json\" -H \"Accept:application/json\" ${FULLURL}" curl -k 
-v -i -X POST -d "${NEWSATORIREQ}" --output "${OUTPUTFILENAME}" --header "Content-Type: application/json" -H "Accept:application/json" "${FULLURL}" 

echo "End ${THISTEST}" 

任意のヘルプ?

答えて

1

あなたの入力および出力ファイルパスは、スクリプト内で定義されていないOUTPATHから構成されています。したがって、OUTPUTFILENAME = "$ {OUTPATH}/SatoriTest1-output"は "/ SatoriTest1-output"になりました。

ルートすなわちでの出力ファイルのチェック、/またはOUTPATHを初期化して試してみてください。

関連する問題