0
0

Goでコンソールアプリのexeファイルを実行する

Posted at

前回、C#でExcelの.xls形式を.xlsx形式に変換するexeファイルを作ったので、それをGo言語で呼び出してみます。

C#でビルドした実行ファイルは、以下のように配置しました。

C:.
│  go.mod
│  main.go
│
└─net6.0
        ExcelConverter.deps.json
        ExcelConverter.dll
        ExcelConverter.exe
        ExcelConverter.pdb
        ExcelConverter.runtimeconfig.json

Goos/execを使ってexeを呼び出します。

package main

import (
	"fmt"
	"os/exec"
)

func main() {
	exePath := "./net6.0/ExcelConverter.exe"
 
	arg1 := "C:\\Users\\tek\\Desktop\\ExcelConverter\\testData\\sample.xls"
	arg2 := "C:\\Users\\tek\\Desktop\\ExcelConverter\\testData\\sample.xlsx"

	cmd := exec.Command(exePath, arg1, arg2)

	output, err := cmd.CombinedOutput()
	if err != nil {
		fmt.Println("Error executing command:", err)
		return
	}

	fmt.Println("Completed")
}

処理の実行

go run .

.xlsxにファイル変換できました:smile:

次は、Go言語のExcelライブラリからファイルを操作してみたいと思います。

Reference

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