0
0

More than 1 year has passed since last update.

OS/実行環境の情報を取得する【Node.js/C#/Python】

Posted at

Node.js/C#/Pythonの3言語にてOS/実行環境の情報の取得方法を調べたのでここに備忘録を記す。

Node.js

"use strict";
const os=require("os");

(function(){
    // プラットフォームID
    console.log(process.platform);
    // OS名
    console.log(os.type());
    // OSバージョン
    console.log(os.release());
    // OSアーキテクチャ
    console.log(process.env.PROCESSOR_ARCHITEW6432||process.arch);

    // Node.jsバージョン
    console.log(process.version);
    // Node.jsのアーキテクチャ
    console.log(process.arch);
})();

ideone

実行結果

# Windows10
win32
Windows_NT
10.0.19042
x64
v16.12.0
x64

# ideone
linux
Linux
4.19.0-16-amd64
x64
v11.12.0
x64

C#

using System;
using System.Runtime.InteropServices;

class Program{
    static void Main(){
        // プラットフォームID
        Console.WriteLine(Environment.OSVersion.Platform);
        // OSバージョン
        Console.WriteLine(Environment.OSVersion.Version);
        // OS名+バージョン
        Console.WriteLine(Environment.OSVersion.VersionString);
        // OSアーキテクチャ
        Console.WriteLine(RuntimeInformation.OSArchitecture);

        // .NETバージョン
        Console.WriteLine(RuntimeInformation.FrameworkDescription);
        // 実行プロセスのアーキテクチャ
        Console.WriteLine(RuntimeInformation.ProcessArchitecture);
    }
}

ideone

実行結果

# Windows10
Win32NT
10.0.19042.0
Microsoft Windows NT 10.0.19042.0
X64
.NET 5.0.11
X64

# ideone
Unix
4.19.0.14
Unix 4.19.0.14
X64
Mono 5.20.1.19 (tarball Thu Apr 11 09:02:17 UTC 2019)
X64

Python

import sys
from os import path
import platform

if __name__=="__main__":
    # プラットフォームID
    print(sys.platform)
    # OS名
    print(platform.system())
    # OSバージョン
    print(platform.release())
    print(platform.version())
    # OS名+バージョン
    print(platform.platform())
    # OSアーキテクチャ
    print(platform.machine())

    # 実行コマンド名
    print(path.splitext(path.basename(sys.executable))[0])
    # Pythonバージョン
    print(platform.python_version())
    # Pythonアーキテクチャ
    print(platform.architecture()[0])
    # Pythonバージョン(REPL起動時のアレ)
    print(str(sys.version))

ideone

実行結果

# Windows10
win32
Windows
10
10.0.19042
Windows-10-10.0.19042-SP0
AMD64
pypy3
3.8.12
64bit
3.8.12 (279d80ac2079, Oct 17 2021, 05:26:02)
[PyPy 7.3.6 with MSC v.1929 64 bit (AMD64)]

# ideone
linux
Linux
4.19.0-16-amd64
#1 SMP Debian 4.19.181-1 (2021-03-19)
Linux-4.19.0-16-amd64-x86_64-with-Ubuntu-19.04-disco
x86_64
python3
3.7.3
64bit
3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.3.0]

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0