2
I am creating a program that works with commands, and I would like this program to be executed by cmd style:
c:\path\folder>meuprograma
>comando arg1 arg2
>comando 1 falhou
>comando2
>comando 2 executado com sucesso!
>exit
c:\path\folder>
While I’m developing everything is working as per, I run my project and it appears to me like this:
(Janela do console é aberta)
>comando arg1 arg2
>comando 1 falhou
>comando2
>comando 2 executado com sucesso!
>exit
(Janela do console é fechada)
What I want to know is, if I compile my program and register it in the Windows variables and I type the above commands it will work? If not, how to make it work.
And how to take the folder in which the program was executed, for example:
C:\Users\Administrador>cd c:/teste
c:\teste>meuprograma
>help << na execução de um comando
How to get the folder the program is running in case c:/test?
My code:
static void Main(string[] args) {
do {
ReadCommand();
RunCommand();
} while (command != "exit");
}
static private void RunCommand()
{
string[] args = command.Split(' ');
if (args.Length > 0)
{
switch (args[0].ToLower())
{
case "exit":
break;
case "help":
Help();
break;
default:
InvalidCommand();
break;
}
}
}
static void Help()
{
string comandos = "\n" +
"Diretório atual: " <VARIAVEL_COM_DIRETORIO_AQUI> +
"help - Lista de comandos\n" +
"set - Seta o valor de um parâmetro, possui 2 parâmetros\n" +
" > param - Nome do parâmetro;\n" +
" > valor - Valor do parâmetro;\n" +
" Ex: [set repository c:/caminho/do/repositorio]\n"+
"get - Retorna o valor do argumento informado, possui 1 parâmetro\n"+
" > param - Nome do parâmetro;\n"+
" Ex: [get repository]";
Console.WriteLine(comandos);
}
If the method
ReadCommand
and theRunCommand
send strings to theConsole.Write
and read strings byConsole.ReadXXX
yes, it will work. Just test, compile the program, go to its folder bycmd
and executes him.– Marciano.Andrade
:O é verdade, não manjo muito de C#, I’m learning now... Anyway, I have another question, I will supplement the question.
– KaduAmaral
@Marciano.Andrade, if you can answer this other question. :)
– KaduAmaral