( C/C++ の場合) #include <stdlib.h> int putenv(char *env) env : 環境変数とその値を次のような形式で与えます. 変数=文字列 また,環境変数を削除したいときは,NULL の文字列,つまり, 変数= のように与えます. ( Java の場合: System クラスの static メソッド) String setProperty(String str1, String str2) str1 : 変数 str2 : 文字列
#include <stdio.h>
#include <stdlib.h>
int main()
{
int sw;
char *str;
sw = putenv("BAS=c:\\basic");
str = getenv("BAS");
printf("sw %d 環境変数 BAS の値は %s\n", sw, str);
return 0;
}
(出力)
sw 0 環境変数 BAS の値は c:\basic
import java.io.*;
public class Test {
public static void main(String args[]) throws IOException
{
String sw, str;
sw = System.setProperty("BAS", "c:\\basic");
str = System.getProperty("BAS");
System.out.println("sw " + sw + " 環境変数 BAS の値は " + str);
}
}
(出力)
sw null 環境変数 BAS の値は c:\basic
| ホームページ | 目次 | 演習解答例目次 | 付録目次 | 索引 |