33 Replies - 3835 Views - Last Post: 27 November 2008 - 12:30 AM
#1
System command & cin.get?
Posted 26 November 2008 - 12:50 PM
How would you get a program to run a system command of whatever the user types. Example: Run nslookup (whatever user types)
Whenever I tried it came up an overload error.
Replies To: System command & cin.get?
#2
Re: System command & cin.get?
Posted 26 November 2008 - 12:54 PM
#include <iostream>
#include <string>
using namespace std;
int main()
{
char command[255];
cout <<" Enter a string to send to the command interface: ";
cin.getline(command, 255);
system(command);
return 0;
}
I tested it with "pause" for example.
#3
Re: System command & cin.get?
Posted 26 November 2008 - 01:41 PM
cout << "type the web address" << endl;
cin.getline
?
system("nslookup (what user typed);
#4
Re: System command & cin.get?
Posted 26 November 2008 - 02:05 PM
#5
Re: System command & cin.get?
Posted 26 November 2008 - 02:07 PM
Now, if you're planning to work with what's returned from the command, i.e., you want to parse the returned data, you should use popen(the command) and read from the FILE* that it returns.
#6
Re: System command & cin.get?
Posted 26 November 2008 - 02:17 PM
KYA, on 26 Nov, 2008 - 01:05 PM, said:
How would you concentrate it into one command without it running nslookup before it gets the address from the user?
and no JackallTrades i'm not planning on getting it to do anything with the info but to run the command. Thanks for the info though.
#7
Re: System command & cin.get?
Posted 26 November 2008 - 02:23 PM
I ran nslookup by itself to verify, it asks for information there as well. So you want to pass an argument to look up before lookup is run and have it do it automatically?
edit: If the latter is the case, concatenating works just fine.
This post has been edited by KYA: 26 November 2008 - 02:25 PM
#8
Re: System command & cin.get?
Posted 26 November 2008 - 02:25 PM
EDIT: How would you concentrate it? Example?
This post has been edited by Blade2021: 26 November 2008 - 02:29 PM
#9
Re: System command & cin.get?
Posted 26 November 2008 - 02:28 PM
#include <iostream>
#include <string>
using namespace std;
int main()
{
char command[100];
cout <<" Enter a string to send to the command interface: ";
cin.getline(command, 100);
char look[255] = "nslookup ";
strcat(look, command);
system(look);
return 0;
}
I tested with 127.0.0.1, returns home, so it appears to work.
#10
Re: System command & cin.get?
Posted 26 November 2008 - 02:46 PM
#include <iostream>
#include <string>
using namespace std;
int main()
{
string command;
cout <<" Enter a string to send to the command interface: ";
cin >> command;
string look("nslookup " + command);
system(look.c_str());
return 0;
}
#11
Re: System command & cin.get?
Posted 26 November 2008 - 02:47 PM
joking
#12
Re: System command & cin.get?
Posted 26 November 2008 - 02:55 PM
Why does input from the user and system get disabled for the program after this line of code is used to turn off the monitor?
EDIT: and is there any other way to get it to not disable input to the program or to turn off the screen for a set amount time? ( to allow changes to the program window without the user seeing)
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
This post has been edited by Blade2021: 26 November 2008 - 02:57 PM
#13
Re: System command & cin.get?
Posted 26 November 2008 - 02:57 PM
#14
Re: System command & cin.get?
Posted 26 November 2008 - 03:40 PM
Also I'm having some trouble with the keybd commands trying to find the keyboard event for pressing down the Y key.
Sorry if this topic is very random and excessive. Just trying to get awnsers to multiple problems without spamming the forum with multiple topics
This post has been edited by Blade2021: 26 November 2008 - 03:42 PM
#15
Re: System command & cin.get?
Posted 26 November 2008 - 04:15 PM
The monitor being turned "off" should not affect the rest of the program's execution.
edited for a typo
This post has been edited by KYA: 26 November 2008 - 04:18 PM
|
|

New Topic/Question
Reply




MultiQuote





|