Problem when executing batch file with HelloWorld.exe %1

C

carolineb2005

I have compiled this simple program which accept arguments on line

using System;
class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine("Hello ", args[0]);
}
}

If I run a batch file HelloWorldRun.batch with

HelloWorld.exe World

It works

but if I use the %1 parameter in the batch
HelloWorld.exe %1
It doesn't seem to work: it just open the dos window.

This is very annoying !
 
W

William Stacey [MVP]

This works. Don't get annoyed, just find the error. You needed a "+" in
your WriteLine line. Or a "Hello: {0}" You tell Console.Writeline your
passing one arg, but did not give the position parm in the string:

using System;
using System.Collections.Generic;
using System.Text;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Hello: " + args[0]);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}

MyBat.bat
--------------
helloworld %1
C:\mybat Hello

Output
----------
Hello: Hello

--
William Stacey [MVP]

carolineb2005 said:
I have compiled this simple program which accept arguments on line

using System;
class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine("Hello ", args[0]);
}
}

If I run a batch file HelloWorldRun.batch with

HelloWorld.exe World

It works

but if I use the %1 parameter in the batch
HelloWorld.exe %1
It doesn't seem to work: it just open the dos window.

This is very annoying !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top