简体   繁体   中英

How to call the .net exe using command prompt

I have implemented downloading the files from FTP with parallel task in C#.net (console application) with WinSCP .NET assembly. Now I am wondering how to run the .net exe through the command prompt. Can you provide how to run the .net exe in the command prompt?

using System;
using WinSCP;

class Example
{
    public static int Main()
    {
        try
        {
            // Setup session options
            SessionOptions sessionOptions = new SessionOptions
            {
                Protocol = Protocol.Sftp,
                HostName = "example.com",
                UserName = "user",
                Password = "mypassword",
                SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx..."
            };

            using (Session session = new Session())
            {
                // Connect
                session.Open(sessionOptions);

                // Download files
                TransferOptions transferOptions = new TransferOptions();
                transferOptions.TransferMode = TransferMode.Binary;

                TransferOperationResult transferResult;
                transferResult =
                    session.GetFiles("/home/user/*", @"d:\download\", false, transferOptions);

                // Throw on any error
                transferResult.Check();

                // Print results
                foreach (TransferEventArgs transfer in transferResult.Transfers)
                {
                    Console.WriteLine("Download of {0} succeeded", transfer.FileName);
                }
            }

            return 0;
        }
        catch (Exception e)
        {
            Console.WriteLine("Error: {0}", e);
            return 1;
        }
    }
}

For this code it generated one exe. I don't know how to execute the exe in the command prompt.

To execute a .exe in the command prompt ( Windows键 + R > cmd), type in (eventually the path &) name of your file :

C:\PathToYourExe\MyProg.exe

Or using relative pathing :

.\folder\subfolder\myprog.exe

To execute a .exe in C# using the command line, use :

System.Diagnostics.Process.Start("CMD.exe","folder/subfolder/myprog.exe");

Visual Studio will generate, depending on the selected configuration (Debug, Release) an .exe file in either the /bin/Debug or /bin/Release folder.

To go there, navigate to that folder using the Windows Explorer. Then type 'cmd' in the address bar. It will open an Command prompt in that location (alternatively you can open a command prompt first and navigate to the location using the 'cd' command).

Once you have the command prompt in that location, type the name of the .exe file. It will be executed.

Note that if you use PowerShell instead of the Command Prompt you need to use ./NameOfExe.exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM