有沒有辦法在java中獲取命令行參數傳遞給程序外main函數? 我正在寫一些代碼,這是我無法控制的更大的應用程序的一部分,我想知道命令行參數是什麼,而不修改main函數。 注意:我已經看過how to get the JVM arguments和how to get the arguments in main,但希望在我們的應用程序的其他部分獲得它,而不必將它們保存在main函數中,這是我無法控制
我有一個循環來解析命令行參數。如果-d或-b參數有一個參數,一切工作正常。但是當我傳遞沒有參數的-d或-b時,腳本進入無限循環。 # Parse command line input
while [ "$#" -gt 0 ]; do
case "$1" in
-d) DOMAIN="$2"; shift 2;;
-b) BITS="$2"; shift 2;;
#include <stdio.h>
#include <string.h>
int myatoi(char *str) {
int i, res = 0;
for (i = 0; str[i] != '\0'; ++i) {
res = res * 10 + str[i] - '0';
return res;
}
}
int ma
我想讓用戶提供一個4位數字作爲參數的配置設置。對於特定設置A,B,C或D,每個數字將對應於True或False狀態。 A B C D
0 1 0 0 # would indicate that the user wants B setting only
1 1 0 1 # would indicate that the user wants the A, B and D set