7 Replies - 363 Views - Last Post: 11 February 2011 - 05:20 PM Rate Topic: -----

#1 thefuzzy0ne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 20-January 11

Prevent application pause on system() calls

Posted 11 February 2011 - 10:24 AM

Hi.

I have an app which uses a call to system() to open a file. The problem is that the application pausess and waits for the opened file to be closed before it will continue again. I assume there's a way I can stop it from doing this. I've tried Googling, but to be honest I'm not too sure what I should be Googling for, so sorry for the seemingly dense question which I'm sure has been answered thousands of times before. I'd appreciate it if someone could tell me what I need to Google for. I've tried Googling for "asynchronous c++ system call" but had no joy. Please could someone tell me what I'm looking for?

Many thanks in advance. :)

Is This A Good Question/Topic? 0
  • +

Replies To: Prevent application pause on system() calls

#2 mi14chal  Icon User is offline

  • D.I.C Head

Reputation: 81
  • View blog
  • Posts: 202
  • Joined: 11-December 10

Re: Prevent application pause on system() calls

Posted 11 February 2011 - 10:31 AM

Call function system in second thread.
Was This Post Helpful? 1
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Prevent application pause on system() calls

Posted 11 February 2011 - 10:43 AM

The bigger question is WHY you're using a system() call to open a file?
Was This Post Helpful? 0
  • +
  • -

#4 thefuzzy0ne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 20-January 11

Re: Prevent application pause on system() calls

Posted 11 February 2011 - 11:12 AM

View Postmi14chal, on 11 February 2011 - 10:31 AM, said:

Call function system in second thread.


Aha! Thanks. I'll look into that.

View PostJackOfAllTrades, on 11 February 2011 - 10:43 AM, said:

The bigger question is WHY you're using a system() call to open a file?


Because I'm a newbie who's just getting some much needed practice. It's an app that will only be run on Windows, but if there's a better way to do it I'm open to suggestions. :)

As I'm sure you can imagine, I'm not yet familiar with all of the functionality C++ has to offer, and nor am I familiar with many of the idioms, but I suspect practice will alleviate most of that.

Thank you both for your replies.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Prevent application pause on system() calls

Posted 11 February 2011 - 11:23 AM

There is most likely a better way to do what you're doing, which is why I was asking. If you're a "newbie", then jumping into threading is a bad idea.

What exactly are you trying to do here?
Was This Post Helpful? 0
  • +
  • -

#6 thefuzzy0ne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 20-January 11

Re: Prevent application pause on system() calls

Posted 11 February 2011 - 04:30 PM

OK, what I'm making at the moment is a sort of follow-on to the standard "Hello, World!" app.

My application displays random jokes from a Web site.

It uses LibcURL to get a page from a Web site, and then it parses some text out of it and displays it in the console. To take it just a little bit further I decided to allow the user to press "S" to save a joke they like. The joke is appended to the end of a file in C:\temp\Jokes.txt. When the user hits "Q" (to quit), I currently use a call to system() to open the text file so it can be saved to a permanent location of the users' choosing.

system("C:\\temp\\Jokes.txt");


This (in theory) opens the file in the users default text editor for them to do as they please. When the file opens, the application remains active until the user closes their text editor. It's not the end of the world, I know, but it's just something I'd like to know how to do eventually, and I figured there's no time like the present. :)

It's an application for a friend of mine who uses Windows, so it's not really a problem that it's platform-dependant. Obviously I'll eventually get around to creating ANSI-compliant code, but for now I'm just playing around to get a feel for how to do things.

This post has been edited by thefuzzy0ne: 11 February 2011 - 04:34 PM

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Prevent application pause on system() calls

Posted 11 February 2011 - 05:08 PM

Look into CreateProcess.
Was This Post Helpful? 1
  • +
  • -

#8 thefuzzy0ne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 20-January 11

Re: Prevent application pause on system() calls

Posted 11 February 2011 - 05:20 PM

Will do. Thanks! :rockon:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1