Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-19-2008, 09:28 AM
marwex89's Avatar   
marwex89 marwex89 is offline
Guru
 
Join Date: Jul 2008
Location: Viking-land!
Posts: 3,995
Rep Power: 30
marwex89 is a jewel in the roughmarwex89 is a jewel in the roughmarwex89 is a jewel in the rough
Send a message via AIM to marwex89
Question C++ system() not working!!?!? (Cygwin bash shell?)

Well, this is embarrassing...
I can't get the system() function to work..
I.e. I get this runtime error: "sh: cls: command not found" when trying:

Code:
system("CLS");
Well, I figured that my programs probably were running within some "Cygwin bash Shell", and not within "cmd.exe". So I try running them from then command prompt. ****. Same result... Have I just forgot some #include....?? It was runtime error though...

I'm using GNU g++ on NetBeans IDE (works great actually, better than Dev-C++ i feel), with WinXP SP2.

Really, this is annoying... I'm able to bypass this using the API, but...
Any "GNUrus", please inform me...
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-19-2008, 09:32 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default Re: C++ system() not working!!?!? (Cygwin bash shell?)

Cygwin consists of ported tools from Unix, and there's no common tool called "cls".
What you're looking for is probably "clear".
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-19-2008, 09:49 AM
marwex89's Avatar   
marwex89 marwex89 is offline
Guru
 
Join Date: Jul 2008
Location: Viking-land!
Posts: 3,995
Rep Power: 30
marwex89 is a jewel in the roughmarwex89 is a jewel in the roughmarwex89 is a jewel in the rough
Send a message via AIM to marwex89
Default Re: C++ system() not working!!?!? (Cygwin bash shell?)

Seems like I have misunderstood something. You cannot actually use the cmd.exe functions with system()? Hmmm... I tried "PAUSE", and it didn't work either.. I thought you could sort of write a batch script with system() if you wanted to... Do I have to use that Cygwin shell? Is there some linking option for this?
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-19-2008, 01:23 PM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default Re: C++ system() not working!!?!? (Cygwin bash shell?)

If you're running it through "cmd.exe" then you should be able to use both "cls" and "pause". To be honest, I've never heard about the system-function not working. It could be an odd error in your compiler, but I don't think so.

You could try including cstdlib, but it will most likely not work either, as it's, like you say, a runtime error.
__________________
05-03-2007 - 11-13-2008

Last edited by v0id; 07-21-2008 at 03:00 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-19-2008, 06:26 PM
marwex89's Avatar   
marwex89 marwex89 is offline
Guru
 
Join Date: Jul 2008
Location: Viking-land!
Posts: 3,995
Rep Power: 30
marwex89 is a jewel in the roughmarwex89 is a jewel in the roughmarwex89 is a jewel in the rough
Send a message via AIM to marwex89
Question Re: C++ system() not working!!?!? (Cygwin bash shell?)

Okay. This is (exactly) what my dear cmd.exe is telling me:

C:\C++\Projects\SysTest\dist\Debug\Cygwin-Windows>systest.exe
sh: PAUSE: command not found

C:\C++\Projects\SysTest\dist\Debug\Cygwin-Windows>


And this is a simple source code example:

Code:
//
// File:   sys_main.cc
// Author: me
// Date: Today
// Built to systest.exe

#include <cstdlib> // As usual
#include <cstdio> // As you mentioned...
#include <windows.h> // Why not..

using namespace std; // Probably smart

int main(int argc, char** argv)
{
    system("PAUSE");
    return (EXIT_SUCCESS);
}
Notice that I have NOT modified anything of importance. This is a basic NetBeans template for a c++ main function. I have NOT modified any compiler/linker options either. Try it and see...

One thing, though:
My TrendMicro PcCillin Antivirus reacts on my program, "Unknown software".
I just press "Allow" and restart. Disabling my AntiVirus does not help (I just tried).

What is happening???
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 07-20-2008, 08:03 AM
marwex89's Avatar   
marwex89 marwex89 is offline
Guru
 
Join Date: Jul 2008
Location: Viking-land!
Posts: 3,995
Rep Power: 30
marwex89 is a jewel in the roughmarwex89 is a jewel in the roughmarwex89 is a jewel in the rough
Send a message via AIM to marwex89
Default Re: C++ system() not working!!?!? (Cygwin bash shell?)

B.U.M.P

Sure I can't be the only one???
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-20-2008, 10:06 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default Re: C++ system() not working!!?!? (Cygwin bash shell?)

Your problem is that your parameters to the system-function are directed to sh (of Cygwin). sh does not recognize "pause" nor "cls" as those are not a part of the Cygwin-package (or Unix). I can't say why that is, and I have like I said never experienced it, or heard about others having the same problem.

You could try opening "cmd(.exe)" and compile and run it by-hand, and see what the result then is, without using Cygwin.
__________________
05-03-2007 - 11-13-2008

Last edited by v0id; 07-20-2008 at 10:09 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-20-2008, 10:15 AM
marwex89's Avatar   
marwex89 marwex89 is offline
Guru
 
Join Date: Jul 2008
Location: Viking-land!
Posts: 3,995
Rep Power: 30
marwex89 is a jewel in the roughmarwex89 is a jewel in the roughmarwex89 is a jewel in the rough
Send a message via AIM to marwex89
Default Re: C++ system() not working!!?!? (Cygwin bash shell?)

Just like I thought... "sh" is not cmd.exe at all...

Thanks for the help
I'll try compiling from cmd later

EDIT:

Now I tried. No way. Still the same. But at least we know that it's not NetBeans' fault, but g++ compiler...
__________________

Last edited by marwex89; 07-20-2008 at 10:28 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-20-2008, 03:27 PM
dargueta dargueta is offline
Guru
 
Join Date: Oct 2007
Age: 18
Posts: 793
Last Blog:
Programs Under the Hoo...
Rep Power: 13
dargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the rough
Default Re: C++ system() not working!!?!? (Cygwin bash shell?)

Try using #include<stdlib.h> instead of #include <cstdlib>. The system() function is defined there too. I'm not sure if it's cross-platform (probably not), but it's worth a try.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 07-20-2008, 06:43 PM
marwex89's Avatar   
marwex89 marwex89 is offline
Guru
 
Join Date: Jul 2008
Location: Viking-land!
Posts: 3,995
Rep Power: 30
marwex89 is a jewel in the roughmarwex89 is a jewel in the roughmarwex89 is a jewel in the rough
Send a message via AIM to marwex89
Default Re: C++ system() not working!!?!? (Cygwin bash shell?)

Thanks for your reply, but it didn't do it either... As v0id said (and me too), it's a runtime issue really.. But can other people do this with g++? Am I the only one with these problems? Can't be...
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Shell, using wget and awk? TIGA General Programming 0 04-11-2008 07:31 PM
[Pascal in Delphi]System to system Krad Pascal/Delphi 5 12-27-2007 02:35 PM
[PHP] Faking Shell Access Through PHP pranky PHP Tutorials 2 03-29-2007 07:28 AM


All times are GMT -5. The time now is 11:46 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 101%


Complete - Celebrate!

Ads