2013-08-01 1 views
1

몇 가지 옵션이있는 프로그램을 실행하려고 시도하고 입력 txt 파일로 가져옵니다.tcl에서 실행 파일을 실행하는 방법은 무엇입니까?

set myExecutable [file join $::env(path_to_the_program) bin executable_name] 
if { ![file exists $myExecutable ] } { 
puts "error" 
} 

if { ![file executable $myExecutable ] } { 
puts "error" 
} 


set arguments [list -option1 -option2] 
set status [catch { exec $myExecutable $arguments $txtFileName } output] 
if { $status != 0 } { 
    puts "output = $output" 
} 

을 그래서 인쇄의 : 그래서 나는이 시도가

output = Usage: executable_name -option1 -option2 <txt_file_name> 
child process exited abnormally 

답변

4

당신은 실제로 실행 당신에게 인수를 제공하지 않았다. 그냥 textFileName. 당신이 목록에 인수를 유지하는 것을 선호하는 경우

set status [catch {exec $myExecutable -option1 -option2 $txtFileName} output] 

또는 : 시도해보십시오 {*} 구문 목록의 원인이됩니다

set status [catch {exec $myExecutable {*}$arguments} output] 

장소에서 확장 할 수 있습니다. 티클에서이 전 버전은 사용하는 것 (8.5)를 첨가 하였다 : 그 간부가 인수 한 세트를 볼 수 있도록 평가 명령 목록을 펼쳤다

set status [catch {eval exec [list $myExecutable] $arguments} output] 

. $ myExecutable 주위에 여분의 [list] 문을 추가하면 인터프리터 패스에 의해 목록으로 취급되지 않도록 내용이 보호됩니다.

관련 문제