Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

To this date one needs to be careful with executing applications and spaces in the path.

For example:

    D:\test>dir
    ...
    08/10/2023  09:29 AM    <DIR>          .
    08/10/2023  09:30 AM    <DIR>          Foo Bar
    08/10/2023  09:35 AM                79 Foo.bat
    ...

    D:\test>dir "Foo Bar"
    ...
    08/10/2023  09:30 AM    <DIR>          .
    08/10/2023  09:29 AM    <DIR>          ..
    08/10/2023  09:35 AM                79 Foo.bat
    ...
        
    D:\test>type Foo.bat
    @echo off
    echo Executable: %0
    echo Path to executable: %~dp0
    echo Params: %*

    D:\test>type "Foo Bar\Foo.bat"
    @echo off
    echo Executable: %0
    echo Path to executable: %~dp0
    echo Params: %*

    D:\test>Foo.bat hello
    Executable: Foo.bat
    Path to executable: D:\test\
    Params: hello
    
    D:\test>Foo Bar\Foo.bat hello
    Executable: Foo
    Path to executable: D:\test\
    Params: Bar\Foo.bat hello
    
    D:\test>"Foo Bar\Foo.bat" hello
    Executable: "Foo Bar\Foo.bat"
    Path to executable: D:\test\Foo Bar\
    Params: hello

    D:\test>
Mess up the quotes and you're executing something one level up.


Right, but my point is that "Program Files" &co were so common that it forced IT people (and everybody else) to handle this correctly. Executing something one level up is not the kind of bug that's going to be unnoticed when it'll be hit so often.

(btw most IT folks prefer powershell, if only because all the management tools are powershell modules)


Nice example!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: