Windows run, in C++

I'm trying to code a program that opens a program. I have a command that I normally run manually in a Windows run (Windows Key + R).

Command:
"C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1"


I tried:
1
2
3
4
5
6
7
8
9
10
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    system("C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1");

}


I’m not sure, system() is the way to go here, and I get an error cause of the spaces. Can anyone help me out?
Run this program:
1
2
3
4
5
6
7
#include <iostream>

int main()
{
    std::cout << "C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.54\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1"
    return 0;
}

Does the string that gets put to the console look like the one you're trying to invoke as a command? Probably not. To explain the differences, take a look at this page: http://en.cppreference.com/w/cpp/language/escape
Pay attention to the fact that dealing with backslashes and double-quotes require special care because they are tokens that C++ itself uses to create string literals.
You need to escape the backslashes.
1
2
3
4
5
6
7
#include <cstdlib>

int main()
{
    system("C:\\Riot Games\\League of Legends\\RADS\\solutions\\lol_game_client_sln\\releases\\0.0.1.54\\deploy\\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator 185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1");

}
@booradley60

I literally put the command from my original post in to the Run dialog box. http://en.wikipedia.org/wiki/Run_command#mediaviewer/File:Run_Windows.png

I’m not sure how to call the program from command-line-interface. I tried your program but nothing happened the program, I’m trying to call, didn't open. The ide gave some warnings because of the backslashes. Also tried to escape the backslashes like KBW suggested.

C:\...\testing\main.cpp||In function 'int main()':|
C:\...\testing\main.cpp |5|warning: unknown escape sequence: '\R' [enabled by default]|
C:\...\testing\main.cpp |5|warning: unknown escape sequence: '\L' [enabled by default]|
C:\...\testing\main.cpp |5|warning: unknown escape sequence: '\R' [enabled by default]|
C:\...\testing\main.cpp |5|warning: unknown escape sequence: '\s' [enabled by default]|
C:\...\testing\main.cpp |5|warning: unknown escape sequence: '\l' [enabled by default]|
C:\...\testing\main.cpp |5|warning: unknown escape sequence: '\d' [enabled by default]|
C:\...\testing\main.cpp |5|warning: unknown escape sequence: '\L' [enabled by default]|
||=== Build finished: 0 error(s), 7 warning(s) (0 minute(s), 1 second(s)) ===|



@kbw When trying to use your solution ill get the same error as before
'c:\Riot' is not recognized as an internal or external command, operable program or batch file.
Last edited on
Sorry, system takes a string, I mistakely just fixed the backslashes in what you posted.
1
2
3
4
5
6
#include <cstdlib>

int main()
{
    system("\"C:\\Riot Games\\League of Legends\\RADS\\solutions\\lol_game_client_sln\\releases\\0.0.1.54\\deploy\\League of Legends.exe\" 8394 LoLLauncher.exe \"\" spectator 185.40.64.163:80 HePSGcqnkxXliRBtWvn7WuZKxxxspYw9 1680414939 EUW1");
}
Last edited on
I get this again

'c:\Riot' is not recognized as an internal or external command, operable program or batch file.


I guess it has something to do with the spaces. Also I'm not sure I can just copy-paste the Run dialog box command in to the cmd.
Last edited on
Topic archived. No new replies allowed.