simple console question  
Author Message
mattdawg





PostPosted: Visual C# Language, simple console question Top

I have a simple console project that I want to pass 2 arguments into. Here is a simple example of the code that I have.

static void Main(string[] args);

{

string somevar = args[0];

string somevar2 = args[1];

doSomething (somevar, somevar2);

}

I want to run the program like this.

C:\testapp.exe "C:\documents and settings\administrator\application data\testapp\" "C:\documents and settings\administrator\application data\testapp\toBeUploaded.zip"

I tried it with and without the quotation marks but it appears that the program is only getting C:\documents for the first string and "and" for the second string. How do I get arount this



Visual C#18  
 
 
Brendan Grant





PostPosted: Visual C# Language, simple console question Top

In your first argument, lose the final \ at the end. From the looks of it the environment is seeing the ending \" as an escape character and keeps running with the string. Yank that \ and things should work just the way you want it to.

 
 
mattdawg





PostPosted: Visual C# Language, simple console question Top

That didn't seem to change anything. I am running this from a command prompt and for some reason your reply made me wonder if maybe the string is too long for dos. Do you know how many characters you can have in a dos command


 
 
mattdawg





PostPosted: Visual C# Language, simple console question Top

yes it seems that the command is too long and I am not getting the last quotation mark and so it is breaking the string down. is there another way to pass parameters into a program
 
 
boban.s





PostPosted: Visual C# Language, simple console question Top

Command is not long. Just as Brendan suggest either remove last backslash from first parameter or replece it with two backslashes:

C:\testapp.exe "C:\documents and settings\administrator\application data\testapp" "C:\documents and settings\administrator\application data\testapp\toBeUploaded.zip"

or

C:\testapp.exe "C:\documents and settings\administrator\application data\testapp\\" "C:\documents and settings\administrator\application data\testapp\toBeUploaded.zip"



 
 
mattdawg





PostPosted: Visual C# Language, simple console question Top

I tried that already it didn't change anything. I still am getting cut off because of the command prompt all my program is getting is

args[0] is "C:\documents and settings\administrator\application data\testapp"

args[1] is "C:\documents

args[2] is and

args[3] is settings\admin

so it's just not getting eveything. if you notice it cuts off inside second string. it's too long and because the second " is not included in the input ot the program it breaks the strings down into multiple string because of the spaces. Is there another way to read data into the file or am I going to have to create a file with the two paths in it and the program will just read the file


 
 
Canuck1





PostPosted: Visual C# Language, simple console question Top

You could try using the old MS-DOS name (8.3 format) for the folder, which would probably be:

C:\DOCUME~1\ADMINI~1\APPLIC~1\TESTAPP

I'm guessing that you should also get rid of the quotes since they are showing up inside the string arguement.

If you ever want to find out the 8.3 format name for a folder or file again, use the command prompt and go to the directory it is contained in. Then type dir /x and you'll see the 8.3 name (if it has one) in the second last column.

Hope that helps.


 
 
boban.s





PostPosted: Visual C# Language, simple console question Top

I just test it and it works with my both examples. You probably have some application version problem and test with old build.

 
 
Mark Benningfield





PostPosted: Visual C# Language, simple console question Top

I tried that already it didn't change anything. I still am getting cut off because of the command prompt all my program is getting is

args[0] is "C:\documents and settings\administrator\application data\testapp"

Look, your first argument has both quotation marks in it.

args[1] is "C:\documents

Look, your second argument only has one quotation mark in it.

args[2] is and

args[3] is settings\admin

so it's just not getting eveything. if you notice it cuts off inside second string. it's too long and because the second " is not included in the input ot the program it breaks the strings down into multiple string because of the spaces. Is there another way to read data into the file or am I going to have to create a file with the two paths in it and the program will just read the file

Hello All.

mattdawg:

If you don't want to listen to the answer, then why ask the question What is happening is that the ending '\' is resulting in the beginning and ending quotes being included in the first command line parameter, instead of delineating it. Add a second '\' to it, and it will behave the way you want it to. Brendan and boban.s are correct. You should listen to them.

HTH.