04-13-2015 07:39 PM
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
Solved! Go to Solution.
04-14-2015 02:19 AM
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.
04-14-2015 08:43 AM - edited 04-14-2015 08:44 AM
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); }