我有一個 MVC 應用程式,其中集成了一個 .net 控制臺應用程式。現在我想傳遞一個從 MVC 模型中的方法回傳的值,并將其作為引數傳遞給控制臺應用程式的 MAIN 方法。
我希望從“PinBlock”函式回傳的“hexString”作為引數傳遞到控制臺應用程式的 Main 方法中。
**MVC Model Function**
public string PinBlock()
{
// PAN Code without first 3 characters and last character
string str1 = Convert.ToString(PAN).Remove(0, 3);
string str2 = str1.Remove(str1.Length - 1, 1);
// Adding 4 0s at the start of the remaining PAN Number
int count = 4;
char someChar = '0';
string AlgoA = str2.PadLeft(count str2.Length, someChar);
Console.WriteLine("ALgoA: " AlgoA);
//Finding the length of the pin code and adding it to the pin code wth 10 'F's
string PinLength = Convert.ToString(APIN);
PinLength = PinLength.ToString();
string result = String.Format("{0,2:X2}", PinLength.Length);
string AlgoB = result APIN "FFFFFFFFFF";
Console.WriteLine("ALgoB: " AlgoB);
long dec1 = Convert.ToInt64(AlgoA, 16);
long dec2 = Convert.ToInt64(AlgoB, 16);
long res = dec1 ^ dec2;
string hexResult = res.ToString("X");
PIN = hexResult;
return hexResult;
}
**MVC Function that attaches Console app with the MVC app**
public string Onclick(string hexResult)
{
using (var process = new Process())
{
process.StartInfo.FileName = @"..\ABL-ESB-DCA\bin\Debug\net6.0\encrypt\ConsoleApp1.exe"; // relative path. absolute path works too.
process.StartInfo.Arguments = hexResult;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.OutputDataReceived = (sender, data) =>
{
Console.WriteLine(data.Data);
};
process.ErrorDataReceived = (sender, data) => Console.WriteLine(data.Data);
Console.WriteLine("starting");
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
var exited = process.WaitForExit(1000 * 10); // (optional) wait up to 10 seconds
Console.WriteLine($"exit {exited}");
}
// ProcessInfo.Start(@"C:\Users\Talha\Desktop\New folder\linkedin\server.exe");
return "BUTTON ONCLICK";
}
**Console app**
internal class Program
{
static void Main(string[] args)
{
ClassLibrary1.Class1 class1 = new ClassLibrary1.Class1(); ;
class1.Perform();
}
uj5u.com熱心網友回復:
在控制臺應用程式中,我們只需將第一個引數輸出為:
Console.WriteLine(arg[0]);
static void Main(string[] args)
{
foreach(string arg in args)
{
Console.WriteLine(arg[0]);
}
ClassLibrary1.Class1 class1 = new ClassLibrary1.Class1(); ;
class1.Perform();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/479175.html
