github.com/apache/beam/sdks/v2@v2.48.2/go/test/integration/internal/jars/run_nonunix.go (about) 1 // Licensed to the Apache Software Foundation (ASF) under one or more 2 // contributor license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright ownership. 4 // The ASF licenses this file to You under the Apache License, Version 2.0 5 // (the "License"); you may not use this file except in compliance with 6 // the License. You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 // Exclude build constraints of package golang.org/x/sys/unix. 17 //go:build !(aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos) 18 // +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!zos 19 20 package jars 21 22 import ( 23 "fmt" 24 "os/exec" 25 "runtime" 26 "time" 27 ) 28 29 // getTimeoutRunner is an OS-specific branch for determining what behavior to use for Run. This 30 // non-unix version does not handle timeout durations. 31 func getTimeoutRunner() runCallback { 32 // Wrap run with error handling for OS that does not support timeout duration. 33 return func(dur time.Duration, jar string, args ...string) (Process, error) { 34 // Currently, we hard-fail here if a duration is provided but timeout is unsupported. If 35 // we ever decide to soft-fail instead, this is the code to change. 36 if dur != 0 { 37 return nil, fmt.Errorf("cannot run jar: duration parameter provided but timeouts are unsupported on os %s", runtime.GOOS) 38 } 39 return run(jar, args...) 40 } 41 } 42 43 // run simply starts up a jar and returns the cmd.Process. 44 func run(jar string, args ...string) (Process, error) { 45 var cmdArr []string 46 cmdArr = append(cmdArr, "java", "-jar", jar) 47 cmdArr = append(cmdArr, args...) 48 49 cmd := exec.Command(cmdArr[0], cmdArr[1:]...) 50 err := cmd.Start() 51 if err != nil { 52 return nil, err 53 } 54 return cmd.Process, nil 55 }