|
Re: Command line: pass string arguments
[Re: AndrewAMD]
#479972
05/10/20 17:21
05/10/20 17:21
|
Joined: Feb 2017
Posts: 1,725 Chicago
AndrewAMD
OP
Serious User
|
OP
Serious User
Joined: Feb 2017
Posts: 1,725
Chicago
|
Thanks, it looks like this feature was just added! Here's some sample code showing it at work. Here, I extract the string "alpha beta" from the command line: // Note: this only works if arbitrary input string is in double quotations.
// example commandline entry:
// zorro -u "alpha beta" -run commandline_string.c
// output: 'alpha beta'
// returns a temporary string with -u output, if it's in double quotations.
string get_u_output(){
int len = strlen(report(3));
string str = zalloc(len);
strcpy(str,report(3));
char* p = strstr(str,"-u \"");
if(!p) return NULL;
if(!strtok(p,"\"")) return NULL;
return strtok(0,"\"");
}
int main(void){
printf("\n\'%s\'",get_u_output());
}
|
|
|
Re: Command line: pass string arguments
[Re: AndrewAMD]
#485020
01/10/22 11:29
01/10/22 11:29
|
Joined: Feb 2017
Posts: 1,725 Chicago
AndrewAMD
OP
Serious User
|
OP
Serious User
Joined: Feb 2017
Posts: 1,725
Chicago
|
You can always use the Windows API directly. Try this: #include<default.c>
#include<windows.h>
LPSTR GetCommandLineA();
API(GetCommandLineA,Kernel32)
// returns a temporary string with -u output, if it's in double quotations.
string get_u_output(){
int len = strlen(GetCommandLineA());
string str = zalloc(len);
strcpy(str,report(3));
char* p = strstr(str,"-u \"");
if(!p) return NULL;
if(!strtok(p,"\"")) return NULL;
return strtok(0,"\"");
}
void main(){
printf("\n\"%s\"",GetCommandLineA());
printf("\n\"%s\"",get_u_output());
printf("\nDone.");
}
|
|
|
|