• Java in Tcl

    From snosniv@21:1/5 to All on Fri Feb 11 10:34:56 2022
    I have a simple batch file which invokes Java to run a conversion algorithm, this works just fine, but I can't seem to get it work within Tcl.

    batch file is:

    cd c:/Users/Downloads/Fit_files
    java -jar C:\Users\Downloads\__Installation_files\FitSDKRelease_21.67.00\java\FitCSVTool.jar -b C:\Users\Downloads\Fit_files\FIT2CSV\INFILE.fit C:\Users\Downloads\Fit_files\FIT2CSV\OUTFILE.csv

    But I can't seem to invoke Java from within Tcl?
    What do I need to do please?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jtyler@21:1/5 to jtyler on Fri Feb 11 12:26:21 2022
    On 2/11/2022 12:23 PM, jtyler wrote:
    On 2/11/2022 10:34 AM, snosniv wrote:
    I have a simple batch file which invokes Java to run a conversion
    algorithm, this works just fine, but I can't seem to get it work
    within Tcl.

    batch file is:

    cd c:/Users/Downloads/Fit_files
    java -jar
    C:\Users\Downloads\__Installation_files\FitSDKRelease_21.67.00\java\FitCSVTool.jar
    -b C:\Users\Downloads\Fit_files\FIT2CSV\INFILE.fit
    C:\Users\Downloads\Fit_files\FIT2CSV\OUTFILE.csv

    But I can't seem to invoke Java from within Tcl?
    What do I need to do please?

    Have you tried:

    exec cmd.exe /c <path-to>test.bat &

    or if you need the process id,

    set pid [exec cmd.exe /c <path-to>test.bat &]


    These assume you don't want to wait for it to finish, hence the &


    Oh, the pid will be the id of the batch job, not the javaw.exe, so
    probably not that useful.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jtyler@21:1/5 to snosniv on Fri Feb 11 12:23:00 2022
    On 2/11/2022 10:34 AM, snosniv wrote:
    I have a simple batch file which invokes Java to run a conversion algorithm, this works just fine, but I can't seem to get it work within Tcl.

    batch file is:

    cd c:/Users/Downloads/Fit_files
    java -jar C:\Users\Downloads\__Installation_files\FitSDKRelease_21.67.00\java\FitCSVTool.jar -b C:\Users\Downloads\Fit_files\FIT2CSV\INFILE.fit C:\Users\Downloads\Fit_files\FIT2CSV\OUTFILE.csv

    But I can't seem to invoke Java from within Tcl?
    What do I need to do please?

    Have you tried:

    exec cmd.exe /c <path-to>test.bat &

    or if you need the process id,

    set pid [exec cmd.exe /c <path-to>test.bat &]


    These assume you don't want to wait for it to finish, hence the &

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From briang@21:1/5 to snosniv on Sat Feb 12 14:50:07 2022
    On Friday, February 11, 2022 at 10:35:00 AM UTC-8, snosniv wrote:
    I have a simple batch file which invokes Java to run a conversion algorithm, this works just fine, but I can't seem to get it work within Tcl.

    batch file is:

    cd c:/Users/Downloads/Fit_files
    java -jar C:\Users\Downloads\__Installation_files\FitSDKRelease_21.67.00\java\FitCSVTool.jar -b C:\Users\Downloads\Fit_files\FIT2CSV\INFILE.fit C:\Users\Downloads\Fit_files\FIT2CSV\OUTFILE.csv

    But I can't seem to invoke Java from within Tcl?
    What do I need to do please?

    You have to take care with file path names in Tcl. The syntax for a pathname is different from a cmd shell. The backslash character (\) is used as an escape character, so in Tcl, to use it in a path name, the character must be escaped:

    java -jar c:\\Users\\Downloads\\__Installation_files\\FitSDKRelease_21.67.00\\java\\FitCSVTool.jar -b C:\\Users\\Downloads\\Fit_files\\FIT2CSV\\INFILE.fit C:\\Users\\Downloads\\Fit_files\FIT2CSV\OUTFILE.csv

    Or you can essentially escape the entire path using braces ({}):
    java -jar {C:\Users\Downloads\__Installation_files\FitSDKRelease_21.67.00\java\FitCSVTool.jar} -b {C:\Users\Downloads\Fit_files\FIT2CSV\INFILE.fit} {C:\Users\Downloads\Fit_files\FIT2CSV\OUTFILE.csv}

    Or you can use forward slashes (/):
    java -jar C:/Users/Downloads/__Installation_files/FitSDKRelease_21.67.00/java/FitCSVTool.jar -b C:/Users/Downloads/Fit_files/FIT2CSV/INFILE.fit C:/Users/Downloads/Fit_files/FIT2CSV/OUTFILE.csv

    Of course in order to run any external program, the [exec] command should be used:

    exec java -jar ...

    To capture any return values, use the [set] command:

    set return_value [exec java -jar ...]

    Also, you can verify that Tcl can find the program using the [autoexec_ok] command:
    if {[autoexec_ok java] ne ""} {
    set return_value [exec java -jar ...]
    }

    -Brian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From snosniv@21:1/5 to briang on Mon Oct 24 06:38:32 2022
    On Saturday, 12 February 2022 at 22:50:10 UTC, briang wrote:
    On Friday, February 11, 2022 at 10:35:00 AM UTC-8, snosniv wrote:
    I have a simple batch file which invokes Java to run a conversion algorithm, this works just fine, but I can't seem to get it work within Tcl.

    batch file is:

    cd c:/Users/Downloads/Fit_files
    java -jar C:\Users\Downloads\__Installation_files\FitSDKRelease_21.67.00\java\FitCSVTool.jar -b C:\Users\Downloads\Fit_files\FIT2CSV\INFILE.fit C:\Users\Downloads\Fit_files\FIT2CSV\OUTFILE.csv

    But I can't seem to invoke Java from within Tcl?
    What do I need to do please?
    You have to take care with file path names in Tcl. The syntax for a pathname is different from a cmd shell. The backslash character (\) is used as an escape character, so in Tcl, to use it in a path name, the character must be escaped:

    java -jar c:\\Users\\Downloads\\__Installation_files\\FitSDKRelease_21.67.00\\java\\FitCSVTool.jar -b C:\\Users\\Downloads\\Fit_files\\FIT2CSV\\INFILE.fit C:\\Users\\Downloads\\Fit_files\FIT2CSV\OUTFILE.csv

    Or you can essentially escape the entire path using braces ({}):
    java -jar {C:\Users\Downloads\__Installation_files\FitSDKRelease_21.67.00\java\FitCSVTool.jar} -b {C:\Users\Downloads\Fit_files\FIT2CSV\INFILE.fit} {C:\Users\Downloads\Fit_files\FIT2CSV\OUTFILE.csv}
    Or you can use forward slashes (/):
    java -jar C:/Users/Downloads/__Installation_files/FitSDKRelease_21.67.00/java/FitCSVTool.jar -b C:/Users/Downloads/Fit_files/FIT2CSV/INFILE.fit C:/Users/Downloads/Fit_files/FIT2CSV/OUTFILE.csv

    Of course in order to run any external program, the [exec] command should be used:

    exec java -jar ...

    To capture any return values, use the [set] command:

    set return_value [exec java -jar ...]

    Also, you can verify that Tcl can find the program using the [autoexec_ok] command:
    if {[autoexec_ok java] ne ""} {
    set return_value [exec java -jar ...]
    }

    -Brian
    Ah, hadn't thought about the escape, Doh. Thanks for the tip (I haven't dabbled in Tcl for a few years since I retired, but have something at home I want to do).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)