0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

OS system command Run ... / Ruby case / Python case / golang case / Nim case

Last updated at Posted at 2021-08-25

Ruby

oscommand.rb
current = "test"
system("ls")
system("mkdir" ,"./#{current}")
#system("rm" , "-r", "./#{current}")
> ruby oscommand.ruby

Python

oscommand.py
import 'os'

os.system("ls")
os.system("mkdir ./test")
#os.system("rm -r ./test")
> python oscommand.py

golang

oscommand.go
package main

import (
    "log"
    "os/exec"
)

func main(){
    title := "test"
    cmd := exec.Command("zip","-4", title + ".zip","-r","./" + title)
    err := cmd.Run()
    if err != nil {                                                                          
        log.Fatal(err)
    }
    cmd = nil
    cmd = exec.Command("rm","-r","./" + title)
    err = cmd.Run()
    if err != nil {
        log.Fatal(err)
    }
    cmd = nil
}
> go run oscommand.go

Nim

oscommand.nim
import os

discard execShellCmd("ls")
discard execShellCmd("echo")
discard execShellCmd("mkdir ./test")
discard execShellCmd("echo")
discard execShellCmd("ls")
discard execShellCmd("rm -r ./test")
discard execShellCmd("echo")
discard execShellCmd("ls")
> nim c -r oscommand.nim

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?