blob: e8c8e753a15633786d0399938145fa270bbf9049 [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 (
Tim Windelschmidtaf821c82024-04-23 15:03:52 +020020 "errors"
Serge Bazanski140bddc2020-06-05 21:01:19 +020021 "log"
22 "os"
23 "os/exec"
24)
25
26func main() {
27 if len(os.Args) < 3 {
28 log.Fatalf("Usage: %s output_file program <args...>", os.Args[0])
29 }
30
31 f, err := os.Create(os.Args[1])
32 if err != nil {
33 log.Fatalf("Create(%q): %v", os.Args[1], err)
34 }
35 defer f.Close()
36
37 args := os.Args[3:]
38 cmd := exec.Command(os.Args[2], args...)
39 cmd.Stderr = os.Stderr
40 cmd.Stdout = f
41
42 err = cmd.Run()
43 if err == nil {
44 return
45 }
46
Tim Windelschmidtaf821c82024-04-23 15:03:52 +020047 var e *exec.ExitError
48 if errors.As(err, &e) {
Serge Bazanski140bddc2020-06-05 21:01:19 +020049 os.Exit(e.ExitCode())
50 }
51
52 log.Fatalf("Could not start command: %v", err)
53}