C/C++ >> ComWizz in C++ Land
Posted by ComWizz on 08:17:00 04-21-2002
Hi all,

I'm starting to use C and C++ it's a blast!
I should have used C++ a few months ago, when I got that C++ book,
anyway I have a question.

In C:
(using unistd.h) system(); or execv(); or execlp(); commands work
I wanna know how to use execvp();, I tried my hardest.

In C++:
I wanna know how to run programs in C++!
eg: blab("program");
I like C++, it is a little easier than C

[ This Message was edited by: ComWizz on 2002-04-22 00:24 ]
Posted by Mintegra on 10:34:00 04-21-2002
http://www.tac.eu.org/cgi-bin/man-cgi?execvp+3 Has something about execvp(), I did not really read it though.

For executing commands in c++, #include and use std::system.

Thank the people in #c++ for this, not me
Posted by KaGez on 10:57:00 04-21-2002
btw, we have a C/C++ section
[addsig]
Posted by MoX on 19:20:00 04-21-2002
He just wanted to make a general anouncement that he has now started C/C++ [addsig]
Posted by KaGez on 19:41:00 04-21-2002
haha
but it has been moved into here anyways
[addsig]
Posted by ComWizz on 20:30:00 04-21-2002
MoX: not really to announce, mostly for help.

The std::system thing worked, But I must ask, is std::system sh-independent??
In other words:

#include

main()
{
int res;

res = std::system("ls");
return(0);
}

Starts "ls" NOT "sh -c ls"

Another question: How do I split a variable into diffirent parts?
eg: blab = "Hi there!" becomes: blab1 = "Hi" and blab2 = "there!"
Posted by MoX on 21:09:00 04-21-2002
To split the string you could parse it for the " ", and memcpy() the first and the second part of it to another place in memory. [addsig]
Posted by ComWizz on 00:24:00 04-22-2002
Thx MoX, I tried using strncpy(); it worked.

Neway, I had a few ideas for things to do with C/C++...

(1) A perl ---> C/C++ or UNIX shell script ---> C/C++ converter
(2) A new programming/scripting language
(3) Implement an already exsisting language

I successfully made a UNIX shell in C++ only using a few lines of code,
I have Glade, and I tried it, it's good.
Posted by seunosewa on 02:45:00 04-22-2002
You didn't write a UNIX shell :- ) in a few lines of code. You wrote an interface to your existing UNIX shell. If you really did write a UNIX shell, then it should run and compile on windows.
Posted by -KEN- on 03:03:00 04-22-2002
-->-->If you really did write a UNIX shell, then it should run and compile on windows.
[addsig]
Posted by seunosewa on 21:40:00 04-22-2002
Thanks, KaGeZ.

I'll like to see the source for the UNIX shell.
Posted by MoX on 22:13:00 04-22-2002
Heh...has somebody compiled bash on Windows? And can you really use it there like with Linux? I just ask, because everytime I boot windows(it happens seldom, but it happens) I soon get angry about how slow a gui is compared to a nice shell. [addsig]
Posted by SilentStrike on 01:52:00 04-23-2002
http://www.cygwin.com
Posted by ComWizz on 07:05:00 05-05-2002
KaGez: I'm not saying UNIX shells can't be compiled on non-UNIX OSes, I'm saying they SHOULDN'T.

And Windows is NOT better than Linux (Period.)

Thanks...
Posted by Flikm on 11:07:00 05-11-2002
http://libsdl.org/Xmingw32
download mingw from there, you get bash with it i believe...
Posted by Cruxus on 08:32:00 06-12-2002
Quote:
On 2002-04-21 20:30, ComWizz wrote:

The std::system thing worked, But I must ask, is std::system sh-independent??
In other words:

#include
std::system("ls");

Starts "ls" NOT "sh -c ls"


No, std::system() operates through the shell; it does not execute processes outright. In fact, because of the slowness of launching a shell to run a command, many programmers dislike using std::system() (the slowness may be more of a Windows 9x/ME thing, though).

By the way, all your good ol' Standard C Library functions are available in C++ as well, unchanged or by appending a c to the beginning of the header name and removing the .h and then using the std namespace.
In other words:

#include <stdio.h>
printf("Something here.\n");
becomes, in C++:
#include <cstdio>
std::printf("Something here.\n");

You can remove the std:: prefix by putting "using namespace std;" at the top of your code, after all the #includes.

Edit: Made post HTML compatible.

[ This Message was edited by: Cruxus on 2002-06-12 08:34 ]