Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7663089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:58:09+00:00 2026-05-31T13:58:09+00:00

I this part of code, instructs my program (which make screenshots) to spawn a

  • 0

I this part of code, instructs my program (which make screenshots) to spawn a command and quit (close) itself. This can be used to switch to a program using a key in my program, such as to spawn “gimp” or another image editor that a user would like to use it.

case SWITCH_TO:
    if( arg ) {
        char commandline[ 256 ];
        snprintf( commandline, sizeof (commandline), "%s &", arg );
        system( commandline );
        cmd->quit = 1;
    }
    break;

For example using:

program-command SWITCH_TO "gimp"

will have my program call system( “gimp &” ), quit (close) itself and run gimp.

program-command SWITCH_TO "fotoxx"

will have my program call system( “fotoxx &” ), quit (close) itself and run fotoxx.

I want my program to check if “commandline” is valid (application found in $PATH) and if not, command “program-command SWITCH_TO” not run and not close my program (“cmd->quit = 1” do this, close program).

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:58:10+00:00Added an answer on May 31, 2026 at 1:58 pm

    As an initial solution, you can try adding a check of the return value of the system() call.

    It will be -1 on error, or else the return status of the program you run. Not sure how the latter behaves when you use & to get a child process. Also not sure if that detaches the child enough from your parent; if not, the child will terminate when you quit your application.

    As others have suggested, look into fork() and exec() calls to do this properly. You can use a plain exec() to replace your process with that of the program you wish to start; if that fails you are still running, and thus you never need to set the quit flag in that case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is part of my code which reads an http response. It's supposed to
I have this part of code in my application. card.getcard(command, function(toproceed,resultscard) { console.log('entry other
My instructor sent me this code, which is supposed to be an integral part
I make a jquery validation, problem is here that this part from code first(first
I am trying to learn and writting this part of code. while testing few
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
It seems that this part of my code is where the exception occurs: c
I just started learning C but I don't understand this part of the code.
The code we're using is straightforward in this part of the search query: myCriteria.Add(
Note : The code in this question is part of deSleeper if you want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.