Search code examples
windowsfiletclmobaxtermtcltk

"open | $filex" couldn't execute existing file on windows only


Below code:

set filex "./run.sh"

if {[file exist $filex]} {
    puts "File exist!"
}

if {[catch {open |$filex r} pipe]} {
    puts "pwd = [pwd]"
    puts "ERROR: $pipe"
}

returns followind message:

File exist!
pwd = F:/
ERROR: couldn't execute ".\run.sh": no such file or directory

The problem is absent in linux OS (script is normally run), appears only in Windows (on CygWin too). The permissions of the file is: 777. Any universal workaround for both OS?


Solution

  • I found workaround for this problem by adding bash after '|' character:

    if {[catch {open "|bash $filex" r} pipe]} {