so I'm trying to send an array from my C# code to a batch file, on which I need to perform a for-each loop.
My C# code:
string MyBatchFile = {the batch file path}
int[] x = {1,2,3};
var process = new System.Diagnostics.Process
{
StartInfo =
{
Arguments = String.Format("{0}", x)
}
};
process.StartInfo.FileName = MyBatchFile;
process.Start();
My batch file:
set array=%1
FOR %%x IN %array% DO (
echo %%x
/*Some more lines here*/
)
pause
This doesnt seem to work, and if I print %array%
I get "System.Int32[]"
. What am I doing wrong?
Note: The main goal is not to print the array, but rather to perform a few actions on each value in the array. The printing is merely an example.
EDIT: I managed to finally do it, found some workaround :) I won't be publishing how I did it, since it's a "duplicate", isn't it? Cheers.