0

I wanted to pass three parameters to other EXE which in project startup location, I successfully did in C but I am not able to do it in C# windows application, Help me how to do it? Following C code works for it

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
char query[100];
int MYNO= 0x1133aa;
sprintf(query, "demo.exe %x test.bin",MYNO);
system(query);
return 0;
}
enter code here

How do i write this code in C#, please help me :(

  • 3
    Possible duplicate of [Launching an application (.EXE) from C#?](https://stackoverflow.com/questions/240171/launching-an-application-exe-from-c) – Alex K. May 31 '17 at 10:29
  • no no its different, here I wanted to pass three parameters to demo.exe and start, Given link https://stackoverflow.com/questions/240171/launching-an-application-exe-from-c shows How can I launch an application using C#? – surajbinorkar May 31 '17 at 10:33
  • 1
    Search the linked page for *Enter in the command line arguments, everything you would enter after the executable name itself* – Alex K. May 31 '17 at 10:36

3 Answers3

0

In visual studio you can also do like that to pass simply or avoiding from comandline argument:

static void Main(string[] args)
{
    if (args == null)
    {
        Console.WriteLine("args is null"); // Check for null array
    }
    else
    {
        args=new string[2];
        args[0] = "welcome in";
        args[1] = "www.overflow.com";
        Console.Write("args length is ");
        Console.WriteLine(args.Length); // Write array length
        for (int i = 0; i < args.Length; i++) // Loop through array
        {
            string argument = args[i];
            Console.Write("args index ");
            Console.Write(i); // Write index
            Console.Write(" is [");
            Console.Write(argument); // Write string
            Console.WriteLine("]");
        }
    }
AlexSandro Cruz
  • 611
  • 5
  • 3
0

See here for documentation: https://msdn.microsoft.com/de-de/library/h6ak8zt5%28v=vs.110%29.aspx

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        // Opens the Internet Explorer application.
        void OpenApplication(string myFavoritesPath)
        {
            // Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe");

            // Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath);
        }

        // Opens urls and .html documents using Internet Explorer.
        void OpenWithArguments()
        {
            // url's are not considered documents. They can only be opened
            // by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com");

            // Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
        }

        // Uses the ProcessStartInfo class to start new processes,
        // both in a minimized mode.
        void OpenWithStartInfo()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
            startInfo.WindowStyle = ProcessWindowStyle.Minimized;

            Process.Start(startInfo);

            startInfo.Arguments = "www.northwindtraders.com";

            Process.Start(startInfo);
        }

        static void Main()
        {
            // Get the path that stores favorite links.
            string myFavoritesPath =
                Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

            MyProcess myProcess = new MyProcess();

            myProcess.OpenApplication(myFavoritesPath);
            myProcess.OpenWithArguments();
            myProcess.OpenWithStartInfo();
        }
    }
}
S. Spindler
  • 546
  • 3
  • 12
0

Try this:

System.Diagnostics.Process.Start("demo.exe","arguments");
Rui Estreito
  • 262
  • 1
  • 10