Crazy-Weird-Makes no sense?

Reply

Join Date: Dec 2008
Posts: 117
Reputation: u8sand is on a distinguished road 
Solved Threads: 15
u8sand's Avatar
u8sand u8sand is offline Offline
Junior Poster

Crazy-Weird-Makes no sense?

 
0
  #1
Jan 17th, 2009
Hello guys. I made a simple program that works like command prompt. You insert a command, it inserts it into system();
why i do this? because im also adding my own commands. so before it goes into system. it checks first if its one of my newly made commands.
Whats the problem?
Well i was trying out a simple thing:

start notepad.exe
but when i got to:
taskkill /IM notepad.exe
it crashed?!!

So i tryed other things, if i do taskkill for anything EXEPT notepad.exe it works and doesent crash.

WTF is the problem?!!? please help. Tyvm guys.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 16,590
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1614
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Crazy-Weird-Makes no sense?

 
0
  #2
Jan 17th, 2009
Don't know what the problem is. Use your compiler's debugger and single-step through the code. Maybe it has a problem with the "/IM" parameter. Maybe that parameter should follow notepad.exe.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 117
Reputation: u8sand is on a distinguished road 
Solved Threads: 15
u8sand's Avatar
u8sand u8sand is offline Offline
Junior Poster

Re: Crazy-Weird-Makes no sense?

 
0
  #3
Jan 17th, 2009
Originally Posted by Ancient Dragon View Post
Don't know what the problem is. Use your compiler's debugger and single-step through the code. Maybe it has a problem with the "/IM" parameter. Maybe that parameter should follow notepad.exe.
Well the command works fine in CMD.exe. and im not completly sure how to use DevC++'s(the compiler im using) single-step debugger.
Maybe i'll bring it to visual studio to debug.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 117
Reputation: u8sand is on a distinguished road 
Solved Threads: 15
u8sand's Avatar
u8sand u8sand is offline Offline
Junior Poster

Re: Crazy-Weird-Makes no sense?

 
0
  #4
Jan 17th, 2009
Ok let me explain this more...

Im making a sort-of remote computer control. Im not adding GUI yet, but i wanted at least to have control to the CMD. because you can do allot from the CMD. so im doing this with a predefined winsock class i found.

  1. #pragma once
  2. #include "Winsock2.h"
  3.  
  4. const int STRLEN = 256;
  5.  
  6. class Socket
  7. {
  8. public:
  9. Socket();
  10. ~Socket();
  11. bool SendData( char* );
  12. bool RecvData( char*, int );
  13. void CloseConnection();
  14. char* GetMessage();
  15. protected:
  16. WSADATA wsaData;
  17. SOCKET mySocket;
  18. SOCKET myBackup;
  19. SOCKET acceptSocket;
  20. sockaddr_in myAddress;
  21. };
  22.  
  23. class ServerSocket : public Socket
  24. {
  25. public:
  26. void Listen();
  27. void Bind( int port );
  28. void StartHosting( int port );
  29. };
  30.  
  31. class ClientSocket : public Socket
  32. {
  33. public:
  34. void ConnectToServer( const char *ipAddress, int port );
  35. };
  36.  
  37. Socket::Socket()
  38. {
  39. if( WSAStartup( MAKEWORD(2, 2), &wsaData ) != NO_ERROR )
  40. {
  41. cerr << "Socket Initialization: Error with WSAStartup\n";
  42. system("pause");
  43. WSACleanup();
  44. exit(10);
  45. }
  46.  
  47. //Create a socket
  48. mySocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
  49.  
  50. if ( mySocket == INVALID_SOCKET )
  51. {
  52. cerr << "Socket Initialization: Error creating socket" << endl;
  53. system("pause");
  54. WSACleanup();
  55. exit(11);
  56. }
  57.  
  58. myBackup = mySocket;
  59. }
  60.  
  61. Socket::~Socket()
  62. {
  63. WSACleanup();
  64. }
  65.  
  66. bool Socket::SendData( char *buffer )
  67. {
  68. send( mySocket, buffer, strlen( buffer ), 0 );
  69. return true;
  70. }
  71.  
  72. bool Socket::RecvData( char *buffer, int size )
  73. {
  74. int i = recv( mySocket, buffer, size, 0 );
  75. buffer[i] = '\0';
  76. return true;
  77. }
  78.  
  79. void Socket::CloseConnection()
  80. {
  81. closesocket( mySocket );
  82. mySocket = myBackup;
  83. }
  84.  
  85. void ServerSocket::StartHosting( int port )
  86. {
  87. Bind( port );
  88. Listen();
  89. }
  90.  
  91. void ServerSocket::Listen()
  92. {
  93. if ( listen ( mySocket, 1 ) == SOCKET_ERROR )
  94. {
  95. cerr << "ServerSocket: Error listening on socket\n";
  96. system("pause");
  97. WSACleanup();
  98. exit(15);
  99. }
  100. acceptSocket = accept( myBackup, NULL, NULL );
  101. while ( acceptSocket == SOCKET_ERROR )
  102. {
  103. acceptSocket = accept( myBackup, NULL, NULL );
  104. }
  105. mySocket = acceptSocket;
  106. }
  107.  
  108. void ServerSocket::Bind( int port )
  109. {
  110. myAddress.sin_family = AF_INET;
  111. myAddress.sin_addr.s_addr = inet_addr( "0.0.0.0" );
  112. myAddress.sin_port = htons( port );
  113.  
  114. if ( bind ( mySocket, (SOCKADDR*) &myAddress, sizeof( myAddress) ) == SOCKET_ERROR )
  115. {
  116. cerr << "ServerSocket: Failed to connect\n";
  117. system("pause");
  118. WSACleanup();
  119. exit(14);
  120. }
  121. }
  122.  
  123. void ClientSocket::ConnectToServer( const char *ipAddress, int port )
  124. {
  125. myAddress.sin_family = AF_INET;
  126. myAddress.sin_addr.s_addr = inet_addr( ipAddress );
  127. myAddress.sin_port = htons( port );
  128.  
  129. if ( connect( mySocket, (SOCKADDR*) &myAddress, sizeof( myAddress ) ) == SOCKET_ERROR )
  130. {
  131. cerr << "ClientSocket: Failed to connect\n";
  132. system("pause");
  133. WSACleanup();
  134. exit(13);
  135. }
  136. }


I made this same program before and it worked. But i wanted it to be easier to add commands. So i made a class for it. In this class it would connect to the client. The server sends info to the client, the client takes that and puts it into system(); then it sends back "Done".
This all works for EVERY COMMAND POSSIBLE exept for "taskkill /IM notoepad.exe"
could it possible be because i use a config.ini file to get the ip? may it not have closed correctly? Heres how i get the ip:

  1. char ip[256];
  2. ifstream fin("config.ini");
  3. if(!fin)
  4. sprintf(ip,"127.0.0.1"); // default ip (Loopback)
  5. else
  6. {
  7. fin.getline(ip,256);
  8. fin.close();
  9. }

then i plug that ip so i can connect to it.

I dont know why every command works fine exept one. Its really weird. Thanks for your help again.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 16,590
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1614
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Crazy-Weird-Makes no sense?

 
0
  #5
Jan 17th, 2009
I never figured out how to use Dev-C++ debugger either -- I always use VC++ because it has such a great debugger. In your programs you may have to use two debugging sessions -- one for client and another for server. With VC++ I've done that successfully quite a few times.

As for your problem: Sorry, but I have no idea what's wrong.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 117
Reputation: u8sand is on a distinguished road 
Solved Threads: 15
u8sand's Avatar
u8sand u8sand is offline Offline
Junior Poster

Re: Crazy-Weird-Makes no sense?

 
0
  #6
Jan 17th, 2009
well ty anyway. Ill try using VC++
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 662
Reputation: Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough 
Solved Threads: 112
Murtan Murtan is offline Offline
Practically a Master Poster

Re: Crazy-Weird-Makes no sense?

 
0
  #7
Jan 17th, 2009
Just wondering...Notepad and other editor like applications tend to respond to a normal 'terminate' message with a user query if their file has been modified, but don't terminate until they get an answer.

Might this be a part of your problem?
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 117
Reputation: u8sand is on a distinguished road 
Solved Threads: 15
u8sand's Avatar
u8sand u8sand is offline Offline
Junior Poster

Re: Crazy-Weird-Makes no sense?

 
0
  #8
Jan 17th, 2009
Strangly, when i do taskkill /F /IM notepad.exe it works.
I just gota remember to use /F i guess.. But i still don't know why it would crash. At least get an error message. but it shouldent crash... Ty
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 468 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC