2016-09-28 72 views
0

我有這樣的代碼誰需要一個Bash的文件並運行它,然後它打印從猛砸在控制檯中proccess:腳本和Java:我怎麼能說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(); 
     } 

    } 
} 

並運行後控制檯它表明我:

測試SatoriTest1將輸出寫入/ SatoriTest1輸出

現在格式化開關輸入文件/ inputfile中

執行卷曲-k -v -i -X POST -d --output/SatoriTest1輸出 --header 「內容類型:應用程序/ JSON」 -H 「接受:應用/ JSON的」/頓悟服務/驗證

末SatoriTest1.sh

我試圖找出在這個「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並試一試。

相關問題