Jump to content
xisto Community
Sign in to follow this  
aks1232001

Prob With My C Code

Recommended Posts

Hi Guys!

this is a wonderful place.. although i wasnt a member till now i have referred to these forms quite a few times for my programming solns :lol:

My problem is :::

I am writing a Code in C using Bloodshed Dev C++ 4.9.9.2 on Windows XP. I wanted to open an executable file from my code. After using the solution mentioned on these forums, I used

system("myprg");

It works fine.. But the prob is that i want my C program to execute this command and then return to the next statement without waiting for me to close the program "mrprog.exe"..

Right now wat happens is suppose my code is:

system("myprog.exe");printf("Hello World");


""Hello World" isnt printed on the screen till i exit the program myprog.exe

Is there any function that can do this job???
Kindly help me plz!

Thanx

Share this post


Link to post
Share on other sites

As far as I know the only way to do what you want properly is to use threads and the fork and wait functions. Implimenting it is non-trivial, but if you really need to be able to do it, do a search for c, threads, and fork on google. You'll need to download an extra library and learn about interrupts. Alternatively, if you're running linux you might be able to get away with system("myprg &");

Share this post


Link to post
Share on other sites

On Windows then you should be able to use the command "start." I'm not sure if it would work in this context, but it does in command prompt- usually if you start a program or batch file, it does the same thing that you're talking about, but start runs it independently. This is what I would do:

system("start /D. /B myprg");
/D. is the path, so if it's in a different directory, use /D"path to its directory"
/B says not to make a new window. If it's a text based thing then take that out.

Share this post


Link to post
Share on other sites

It works!!!!!!!!!!!!!!!!!!!!!!!! :lol:

well i tried

system("start /D. /B myprg");

N it worked to perfection...
Thanks a lot Beeseven n Windandwater <_<



But there is a small new problem..
In my code written in C using Dev C++ created by Bloodshed (OS: Windows XP)
i want to access the serial ports.. I.e send data to them in order to control a motor that is connnected to my computer...

I know its easy to do that in win16 using turboC and function outportb()...but in win32 (i.e Dev C++) how do i do it???

I read some info on stuff like win API but a newbie like me found it really really confusing to do it..

are there any simples functions like outport() which i can use in my compiler???

Thanx a lot for all the help guys!

Eagerly awaiting ur reply :lol:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.