Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Command Line Arguments that contain hyphens

I am attempting to pass command line arguments to a console application(Computer Language Compiler).

My Problem: The argument I am passing contains a hyphen character and it is causing an error "- was unexpected command/character".

This is the command line argument I am using(12d.exe is the application/compiler):

12d.exe "C:/Staff - Name/abc.4dm"

It seems that its looking at the '-' as a command and not part of a directory/string. Maybe I can use a batch file to perform this command line and reformat the directory path? You know how like in HTTP POST I can use urlencode to format post commands, maybe I can encode the command line in a batch file.

like image 822
sazr Avatar asked May 01 '12 23:05

sazr


2 Answers

You could try adding a ^ to "escape" the hyphen in the batch making batch ignore it.

12d.exe "C:/Staff ^- Name/abc.4dm"
like image 31
iesou Avatar answered Sep 25 '22 09:09

iesou


It seems that 12d.exe does not understand some valid filenames, shame on 12d.exe.

There are a couple actions you might do,

  1. try to pass the short filename instead. It may work in some cases where the hyphen - is off the right of the string. Not in your case, though, as it will probably translate as STAFF-~1 or something similar.

    call :invoke12d "Staff - Name\abc.4dm"
    goto :eof
    :invoke12d
    12d %~s1
    goto :eof
    
  2. or create a junction, a symbolic link, to call the directory with another name that does not contain hyphens. See this http://technet.microsoft.com/en-us/sysinternals/bb896768 for more information and to download a simple tool.

    junction staffnam "Staff - Name"
    12d.exe "staffnam/abc.4dm"
    
like image 71
PA. Avatar answered Sep 23 '22 09:09

PA.