PDA

You are currently viewing a search engine-friendly (archive) version of this page.

View Full Version : pass command to OS with C


afterthought
January 16, 2001, 01:59 pm
How do I pass a command, such as 'net view' or 'net use' to the operating system using C?

Is this even possible?

I know C++ has 'system()', but I have not been able to get it working. I may be missing something. What do I need?

My background in C is still very limited. I could very easily miss the obvious. Keep this in mind when posting.



------------------
To be, or not to be . . .

Wait, what was the question?

MikeFoster
January 17, 2001, 12:24 am
You are correct. system() is a function that will pass a command line to the OS's command interpreter.

What error message are you getting? Is it a compile-time or run-time message? What OS are you running on? Are you #includeing the correct header file? Show us a code fragment.

------------------
Mike Foster, Moderator, Webmastering/HTML, HelpFromTechs.com (http://www.helpfromtechs.com/cgi-bin/ubb/ultimate.cgi)

afterthought
January 17, 2001, 03:44 pm
Let me poke around for a while. Last night I just had an Intermediate C class. I learned the differences between some standard C compilers (Borland C++ and MS Visual C++). I also learned that the last class I took- the compiler was not picky about my header files (Borland's 'antique', DOS based compiler).

I think you are right, the answer may be in my headers. It may also be proper usage of my compiler. I will let you know and post any problems or resolutions.

BTW, I posted a question regarding compilers that tangent this post: http://www.helpfromtechs.com/ubb/Forum14/HTML/000010.html




------------------
To be, or not to be . . .

Wait, what was the question?

MikeFoster
January 17, 2001, 11:41 pm
Good Luck! http://www.helpfromtechs.com/ubb/smilies/smile.gif

------------------
Mike Foster, Moderator, Webmastering/HTML, HelpFromTechs.com (http://www.helpfromtechs.com/cgi-bin/ubb/ultimate.cgi)

MikeFoster
January 27, 2001, 09:13 pm
afterthought, how did it go? Did you get it working? system() let's you do some really cool stuff, eh?

------------------
Mike Foster, Moderator, Webmastering/HTML, HelpFromTechs.com (http://www.helpfromtechs.com/cgi-bin/ubb/ultimate.cgi)

afterthought
January 28, 2001, 07:50 pm
I finally got it working. Very nice. My problem was a combination of things. Header files and compilers. Mostly my familiarity with the compiler.

Thanks again!



------------------
Free the Cajun Man.

MikeFoster
January 28, 2001, 11:30 pm
Great! http://www.helpfromtechs.com/ubb/smilies/smile.gif

------------------
Mike Foster, Moderator, Webmastering and HTML, HelpFromTechs.com (http://www.helpfromtechs.com/cgi-bin/ubb/ultimate.cgi)

reddsteel
January 30, 2001, 10:46 pm
Good job! http://www.helpfromtechs.com/ubb/smilies/smile.gif

------------------
:: reddsteel ::
Moderator => HelpFromTechs.com
In a world without fences, who needs Gates?

Tonker
February 21, 2001, 11:11 am
Since my friend and I were looking at this last night, I though I would put in my $0.02 worth, even though the issue seems to be resolved. http://www.helpfromtechs.com/ubb/smilies/smile.gif

I think system() is a general call to get the operating system to run a command and return back to your app. There are other options, though depending on what you want to accomplish and what OS you're building for.

I had to make an executable app to launch a java application. On unix I ended up using one of the exec() family. execlp() will use your system's PATH environment variable to make the system call. On windows (VisualC++) I ended up using an unduly complicated CreateProcess call. These functions differ from system() in that they create a new process, or transfer control from your application to the new process, as I understand it.

system() I guess is the best choice if you want to execute another application and continue processing withing your own application, whereas exec and CreateProcess seem to be useful for launching an application in it's own space.

Just wanted to get that out while I still remember.

------------------

afterthought
February 21, 2001, 06:18 pm
Thanks, Tonker!

This is very useful!

------------------
Free the Cajun Man.

tweakthis
February 23, 2001, 07:51 pm
But ask tonker if he's got his sound card working yet! And has he asked his sister (the family hardware nut) for any help?

I know, I know, not my forum...I just like to pop in every now and then so I can shake my head and go, "Say what???" http://www.helpfromtechs.com/ubb/smilies/confused.gif
Besides that, it also comes after 'useful links'. http://www.helpfromtechs.com/ubb/smilies/wink.gif
------------------
Moderator, General Discussion, helpfromtechs.com (http://www.helpfromtechs.com/cgi-bin/ubb/Ultimate.cgi) and Useful Links (http://www.helpfromtechs.com/cgi-bin/ubb/forumdisplay.cgi?action=topics&number=13&SUBMIT=Go)
I can be reached at tweakthis@helpfromtechs.com

<FONT COLOR="#800080" SIZE="1" FACE="Verdana, Arial">This message has been edited by tweakthis on February 23, 2001 at 04:52 PM</font>

MikeFoster
February 25, 2001, 12:51 am
Pop in anytime tweakthis! http://www.helpfromtechs.com/ubb/smilies/smile.gif

------------------
Mike Foster : moderator : HelpFromTechs.com
Tell us about your favorite HTML editor! (http://www.helpfromtechs.com/ubb/Forum8/HTML/000030.html)

tweakthis
February 27, 2001, 09:37 am
Thanks, Mike. I might just spend a couple of days here. Have a rest. http://www.helpfromtechs.com/ubb/smilies/wink.gif

------------------
Moderator, General Discussion, helpfromtechs.com (http://www.helpfromtechs.com/cgi-bin/ubb/Ultimate.cgi) and Useful Links (http://www.helpfromtechs.com/cgi-bin/ubb/forumdisplay.cgi?action=topics&number=13&SUBMIT=Go)
I can be reached at tweakthis@helpfromtechs.com