LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass the command line argument (argc and argv) to a LabVIEW built shared library.

Solved!
Go to solution

Hello,

 

I have successully use this trick to build a LabVIEW application that runs on Linux without X Display.

 

http://digital.ni.com/public.nsf/allkb/5D6EC36DCF43343786257449006919E6

 

I'd like to know if it's possible to pass the command line arguments ( ./TEST A B C D) directly into the shared library without having to pass the arguments using a array of strings which would require to write code using DSNewHandle, DSSetHandleSize, extract the arguments and ..... (I'm not proficient in C, but if I don't have a choice I will do it and improve my C skills).

 

int main(int argc, char *argv[])
{
        Test(argc, argv);
        return 0;
}

 

Thanks,

 

Michel

 

 

0 Kudos
Message 1 of 3
(3,788 Views)
Solution
Accepted by topic author Michel_Gauvin

Well, you can always flatten it back into a space separated single string and pass it like that. Basically reverse what the OS does when it calls your main function with the command line parameters. And while the first element in the array is always the program name itself you can just skip that here, but then format all the rest into a single string.

Rolf Kalbermatter
My Blog
Message 2 of 3
(3,747 Views)

This works good. You may comment if it can be optimized or if you observe any pitfall in this small code, thanks.

 

#include "Test.h"
#include <stdio.h>
#define MAX_LEN 256

int main(int argc, char *argv[])		
{
	char buffer[MAX_LEN];
	buffer[0] = 0;
	int offset = 0;
	int written = 0;
	while(argv++,--argc) {
		int toWrite = MAX_LEN-offset;
		if (argc == 1) {
			written = snprintf(buffer+offset, toWrite, "%s", *argv);
		}
		else {
			written = snprintf(buffer+offset, toWrite, "%s;", *argv);
		}
		if(toWrite < written) {
		break;
		}
		offset += written;
	}
	printf("%s\n", buffer);

	Test (buffer);
	return(0);
}

 

0 Kudos
Message 3 of 3
(3,710 Views)