开发者

Passing special chars to exe through command prompt

I want to pass mix of most of all special chars a one command line arguments to an exe. The exe is invoked by bat file.

syntax is something like this:

sample.bat file

set arg1="newData!@#$%%^&()(*)://///;><|+=-"

MyPath="D:\MyExeLocation" %MyPath%\MyExe.exe %arg1%

Above one is working but it's not working if i add double quote (") in the arg1 string. would you please tell me how to escape it. I tried escaping it by ^, " and \ also. it's not working. if i do with \, string includes \ as well along with double quote. ot开发者_开发百科her two ^ and " are not working throwing some error

Ultimately i want to pass any special chars in arg1. Would you please give me your suggestions???

Advance Thanks Robert.


Forget about the single quote I old you. I've used this in a XML file. Nevermind.

You must double the double quote if you want a single double quote. For example if you want to pass the string "a" to your application you must use """a""" as parameter.

For testing the parameters I use the following bat file

set var=%*

c:\cmd.exe %var%

and cmd.exe is a the following C# program

public class Program
{
    static void Main(string[] args)
    {
        if (args != null)
        {
            Console.WriteLine(args.Length);

            foreach (var s in args)
            {
                Console.WriteLine(s);
            }
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜