VMware {code} Community
arindamchoudhur
Contributor
Contributor

How to store the result of "which gcc"?

using VIX api I want to copy a C file into the guest and compile it and run it.

the problem is with compiling the C program. Here we need to supply the full path of gcc. but I full path might not be always known.

So, how to run "which gcc" in the guest than use the result to compile it?

Thanks in advance.

-Arindam

Tags (1)
Reply
0 Kudos
2 Replies
cblomart
Enthusiast
Enthusiast

Do mean to upload a source file and a script to compile it?

in this case, using bash it could be something like this

----

#!/bin/bash

gcc=$(which gcc)

$gcc source.c -o program

----

arindamchoudhur
Contributor
Contributor

what if without script.

char *command;

printf("compiling the c file\n");
jobHandle = VixVM_RunProgramInGuest(vmHandle,
                   command,                // command
                   "/home/arindam/HelloWorld.c -o /home/arindam/HelloWorld",   // cmd args
                   0,                        // options
                   VIX_INVALID_HANDLE,       // prop handle
                   NULL,                     // callback
                   NULL);                    // client data
err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE);
Vix_ReleaseHandle(jobHandle);
if (VIX_FAILED(err)) {
fprintf(stderr, "failed to compile program in virtual machine '%s'(%"FMT64"d %s)\n",
vmpath, err, Vix_GetErrorText(err, NULL));
goto abort;
}

where the command string will store the "which gcc".

-Arindam

Reply
0 Kudos