Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass variable argument to exe?

Okay, let's say that I have b.exe, which takes a string argument. I want to invoke b.exe within a.cpp, with system:

    string s1 = "hallo";
    system("b.exe s1");
    printf("s1 after invoke = %s",s1);

and this is the code in b.cpp:

    int main(string s)
    {
         s = "hello world";
         return 0; 
    }

what I want is, when I run a.exe, the output will be:

    s1 after invoke = hello world

is it possible to do that? basically, i just want to pass a variable to an exe, but it must be by reference, not only by value because I want that variable to be processed and modified within the exe that I invoked. I've already searched the solution on the internet, but it only provides me tha way to pass a variable by value to the exe, not by reference..

any suggestion will be very appreciated, but if possible, I want the suggestion in the form of the above correction code and include files, if any. thanks for your help :)

like image 538
zia Avatar asked Jul 23 '11 06:07

zia


People also ask

How do I pass a command line argument to exe?

Open a command prompt (Windows+R, type "cmd" and hit enter). Then change to the directory housing your executable ("cd enter-your-directory-here"), and run the command with the parameters.

How do I pass a command line argument in CMD?

For example, entering C:\abc.exe /W /F on a command line would run a program called abc.exe and pass two command line arguments to it: /W and /F.

Can we pass parameters to batch file?

Batch parameters (Command line parameters): In the batch script, you can get the value of any argument using a % followed by its numerical position on the command line. The first item passed is always %1 the second item is always %2 and so on. If you require all arguments, then you can simply use %* in a batch script.

How can I pass arguments to a batch file from a source text file?

It can be solved with reading from a temporary file a remarked version of the parameter. @echo off SETLOCAL DisableDelayedExpansion SETLOCAL for %%a in (1) do ( set "prompt=" echo on for %%b in (1) do rem * #%1# @echo off ) > param. txt ENDLOCAL for /F "delims=" %%L in (param.


1 Answers

It is not possible to modify command line arguments among different processes. s1 is known only to A.CPP, and s is only known to B.CPP.

like image 80
Ajay Avatar answered Sep 20 '22 17:09

Ajay