blob: a0fb709e0c5997a794ca7e0a0151783905710e26 [file] [log] [blame]
Serge Bazanski140bddc2020-06-05 21:01:19 +02001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17package main
18
19import (
20 "log"
21 "os"
22 "os/exec"
23)
24
25func main() {
26 if len(os.Args) < 3 {
27 log.Fatalf("Usage: %s output_file program <args...>", os.Args[0])
28 }
29
30 f, err := os.Create(os.Args[1])
31 if err != nil {
32 log.Fatalf("Create(%q): %v", os.Args[1], err)
33 }
34 defer f.Close()
35
36 args := os.Args[3:]
37 cmd := exec.Command(os.Args[2], args...)
38 cmd.Stderr = os.Stderr
39 cmd.Stdout = f
40
41 err = cmd.Run()
42 if err == nil {
43 return
44 }
45
46 if e, ok := err.(*exec.ExitError); ok {
47 os.Exit(e.ExitCode())
48 }
49
50 log.Fatalf("Could not start command: %v", err)
51}