3 Replies - 228 Views - Last Post: 31 December 2019 - 04:03 PM Rate Topic: -----

#1 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 815
  • Joined: 15-December 14

Input data while using cmd

Posted 31 December 2019 - 12:11 PM

Trying to write a program to allow the users to change networks. The employees this program is meant for aren't tech savvy and I wanted to make it easy for them to change to different networks when needed.

I've previously written the code in c++ and I've tried using c# to recreate the program without any luck.
but I wanted to re do it in c# since thats the language my employer uses.

So, I've been doing some reading and found that using c# I can write things when I open cmd using
StandardInput.WriteLine();

Is there a way to input data? I looked online and couldn't find an answer

This is how I wrote the program in c++

    bool connect = false;
    while(true)
    {
        system("netsh wlan show profiles");//shows all networks
        std::cout << "Type the name of the network you want to join:" << std::endl;
        std::cout <<"Type main to go back to the main menu" << std::endl;
        std::string join;
        std::cin >> join;
        if(join == "main" || join == "Main")
            break;
        std::string connectcmd = "netsh wlan connect name = ";
        connectcmd.append(join);
        const char* concmd = connectcmd.c_str();
        connect = system(concmd);
        if(connect == true)
            std::cout << "\nConnecting to a network\n" << std::endl;
    }



Is This A Good Question/Topic? 0
  • +

Replies To: Input data while using cmd

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15498
  • View blog
  • Posts: 62,060
  • Joined: 12-June 08

Re: Input data while using cmd

Posted 31 December 2019 - 01:56 PM

Like console.readline / console.writeline?

https://docs.microso...etframework-4.8
Was This Post Helpful? 0
  • +
  • -

#3 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 815
  • Joined: 15-December 14

Re: Input data while using cmd

Posted 31 December 2019 - 02:42 PM

Yes. I've found examples on C# of writing things on the screen using StandardInput.WriteLine(). But I haven't been able to find a way to being able to input information. Although my C++ program works, I would really like to have a working version in C#.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7239
  • View blog
  • Posts: 24,542
  • Joined: 05-May 12

Re: Input data while using cmd

Posted 31 December 2019 - 04:03 PM

Just like I've told you on your other thread, this in C++
std::string join;
std::cin >> join;


is simply this in C#:
string join;
join = Console.ReadLine();



Can you link to some of the examples of:

View Postalbert003, on 31 December 2019 - 04:42 PM, said:

I've found examples on C# of writing things on the screen using StandardInput.WriteLine().

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1