Menu

#984 Wrong directory separator character used in external command placeholders on Windows

5.3
closed-fixed
None
4
2020-08-03
2020-02-28
Andre Oehme
No

I want to use the external external_command (Preferences -> Saving and Output) with placeholders (e.g. ${targetRoot}) under Windows 10 operating system to copy genetrated files to an other directory.

if I use:

cmd /c move /Y  "${targetRoot}${fileName}" "C:\temp\"

the placeholders containing the wrong directory separator character ('/' instead on '\').

(tested with

cmd /c echo move /Y  "${targetRoot}${fileName}" "C:\temp\" >>C:\temp\Logfile.txt

)

This could be read automatically from environment or set by an extra option.

Discussion

  • Aaron Madlon-Kay

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,12 +1,17 @@
     I want to use the external external_command (preferences -> Saving and Output)  with placeholders (e.g. ${targetRoot} )under windows 10 operating system to copy genetrated files to an other directory.
    
     if I use:
    +
    +```sh
     cmd /c move /Y  "${targetRoot}${fileName}" "C:\temp\"
    +```
    
     the placeholders containing the wrong directory separator character ('/' instead on '\').
    
     (tested with 
    +```sh
     cmd /c echo move /Y  "${targetRoot}${fileName}" "C:\temp\" >>C:\temp\Logfile.txt
    +```
     )
    
     This could be read automatically from environment or set by an extra option.
    
     
  • Aaron Madlon-Kay

    I can confirm that this is an issue with the commands you used. Some Windows shell commands can handle /-delimited paths and some cannot:
    https://stackoverflow.com/a/10526678/448068

    A workaround would be to use something other than cmd/move that can interpret the paths correctly, or wrap your entire operation in a script that can fix up the paths as appropriate.

     

    Last edit: Aaron Madlon-Kay 2020-02-29
    • Briac Pilpré

      Briac Pilpré - 2020-02-29

      I think this can be solved by using the canonical path when doing the variable expansion, as the java.io.FileSystem.canonicalize(String) method recreates the path with the proper filesystem separator character.
      It's safer to do that just for the variable expansion since I suspect other part of the application rely on the path separator to be /.

       
  • Aaron Madlon-Kay

    canonicalize actually hits the filesystem, which can be costly in some cases (hot loops, spinning disks, network drives). I think it's adequate to handle this textually, e.g. path.replace('/', File.separatorChar).

    It's safer to do that just for the variable expansion since I suspect other part of the application rely on the path separator to be /.

    Yes, I agree. And you're right; everything is normalized to / for internal use.

     

    Last edit: Aaron Madlon-Kay 2020-02-29
  • Briac Pilpré

    Briac Pilpré - 2020-02-29

    Fixed in [0e89bf]

     

    Related

    Commit: [0e89bf]

    • Aaron Madlon-Kay

      Thank you, that’s perfect.

       
  • Briac Pilpré

    Briac Pilpré - 2020-02-29
    • status: open --> open-fixed
     
  • Aaron Madlon-Kay

    • assigned_to: Briac Pilpré
    • Group: 4.3.2 --> 5.3
     
  • Aaron Madlon-Kay

    • summary: Directory separator character in placeholders at External_commands --> Wrong directory separator character used in external command placeholders on Windows
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,4 @@
    -I want to use the external external_command (preferences -> Saving and Output)  with placeholders (e.g. ${targetRoot} )under windows 10 operating system to copy genetrated files to an other directory.
    +I want to use the external external_command (Preferences -> Saving and Output)  with placeholders (e.g. `${targetRoot}`) under Windows 10 operating system to copy genetrated files to an other directory.
    
     if I use:
    
     
  • Aaron Madlon-Kay

    • status: open-fixed --> closed-fixed
     
  • Aaron Madlon-Kay

    Fixed in OmegaT 5.3.0.

     

Log in to post a comment.

MongoDB Logo MongoDB