LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2014, 12:14 AM   #1
pradeepkondipudi
LQ Newbie
 
Registered: Jun 2014
Posts: 1

Rep: Reputation: Disabled
how to pass string or key between exes in c++, eclipse


Hi, I have an application which has two child processes. The first exe should call the second exe. The second exe should execute after confirming a valid license key from first exe. I am not able to communicate between them. Please any suggestions.
Thanks
 
Old 06-17-2014, 03:06 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Your main application can fork a child process, and then use execv() to execute your 'first' executable that validates the key.

The main application can check the exit status of the 'first' process using waitpid(). This call will block the main application from continuing until the 'first' process completes.

If the returned status is good (typically this is a value of 0), then you can do something similar to launch your 'second' process.

For example:
Code:
#include <iostream>
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char** argv)
{
    const char* licenseKey = "!@#123#@!";

    pid_t keyval_pid = fork();

    if (keyval_pid == 0)
    {
        // In child-process...

        // Set up args to launch key-validation (i.e. 'first') process.
        char** args = new char*[3];
        args[0] = strdup("./first");
        args[1] = strdup(licenseKey);
        args[2] = 0;

        execv(args[0], args);
    }

    // Await status from key-validation process.
    int status;
    waitpid(keyval_pid, &status, 0);

    if (status != 0)
    {
        std::cerr << "Key is not valid." << std::endl;
        return status;
    }

    std::cout << "Safe to launch second child process." << std::endl;
}
 
Old 06-17-2014, 04:16 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you can also check how named pipes work (see examples)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Parse string tokens and pass remaining as parameter yaplej Programming 7 07-12-2013 12:55 PM
[SOLVED] Pass space (or string escaped) as argument to shell script. scmbg Programming 1 10-07-2009 10:15 AM
MDCrack cracks key with pass but not pass with key?... lynx5 Linux - Security 1 02-02-2008 05:49 PM
Bash: how do I pass a double quoted string to a command? Nylex Programming 8 04-18-2007 09:36 AM
pass a string to a named pipe sahel Programming 1 01-05-2006 07:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration