Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

C++ system() not working!!?!? (Cygwin bash shell?)

form

  • Please log in to reply
26 replies to this topic

#1 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 19 July 2008 - 05:28 AM

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

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...
  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#2 v0id

v0id

    Retired

  • Retired Mod
  • PipPipPipPipPipPipPipPip
  • 2313 posts

Posted 19 July 2008 - 05:32 AM

Cygwin consists of ported tools from Unix, and there's no common tool called "cls".
What you're looking for is probably "clear".
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#3 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 19 July 2008 - 05:49 AM

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?
  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#4 v0id

v0id

    Retired

  • Retired Mod
  • PipPipPipPipPipPipPipPip
  • 2313 posts

Posted 19 July 2008 - 09:23 AM

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.

Edited by v0id, 20 July 2008 - 11:00 PM.

  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#5 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 19 July 2008 - 02:26 PM

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:

//
// 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???
  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#6 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 20 July 2008 - 04:03 AM

B.U.M.P :D

Sure I can't be the only one???
  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#7 v0id

v0id

    Retired

  • Retired Mod
  • PipPipPipPipPipPipPipPip
  • 2313 posts

Posted 20 July 2008 - 06:06 AM

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.

Edited by v0id, 20 July 2008 - 06:09 AM.

  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#8 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 20 July 2008 - 06:15 AM

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...

Edited by marwex89, 20 July 2008 - 06:28 AM.

  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#9 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 20 July 2008 - 11:27 AM

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.
  • 0

#10 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 20 July 2008 - 02:43 PM

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...
  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#11 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 20 July 2008 - 05:50 PM

Are you running Unix or some other OS?
  • 0

#12 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 20 July 2008 - 06:03 PM

WinXP SP2
Stable stuff, I thought..
  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download