Skip to content

Commit

Permalink
Set up environment when calling zowex
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <[email protected]>
  • Loading branch information
t1m0thyj committed Jan 30, 2025
1 parent d37e731 commit dcfcdbe
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 31 deletions.
29 changes: 29 additions & 0 deletions native/golang/cmdutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

package main

import (
"os"
"os/exec"
"path/filepath"
)

func buildExecCommand(args []string) *exec.Cmd {
cmd := exec.Command(args[0], args[1:]...)
exePath, err := os.Executable()
if err != nil {
panic(err)
}
cmd.Dir = filepath.Dir(exePath)
cmd.Env = append(os.Environ(), "_BPXK_AUTOCVT=ON")
return cmd
}
21 changes: 10 additions & 11 deletions native/golang/ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"fmt"
"log"
"os"
"os/exec"
"strings"
)

Expand All @@ -34,7 +33,7 @@ func HandleReadDatasetRequest(jsonData []byte) {
if hasEncoding {
args = append(args, "--encoding", dsRequest.Encoding)
}
out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
return
Expand All @@ -49,7 +48,7 @@ func HandleReadDatasetRequest(jsonData []byte) {
}
v, err := json.Marshal(dsResponse)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand Down Expand Up @@ -83,7 +82,7 @@ func HandleWriteDatasetRequest(jsonData []byte) {
if len(dsRequest.Encoding) > 0 {
args = append(args, "--encoding", dsRequest.Encoding)
}
cmd := exec.Command(args[0], args[1:]...)
cmd := buildExecCommand(args)
stdin, err := cmd.StdinPipe()
if err != nil {
log.Println("Error opening stdin pipe:", err)
Expand Down Expand Up @@ -119,7 +118,7 @@ func HandleWriteDatasetRequest(jsonData []byte) {
}
v, err := json.Marshal(dsResponse)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand All @@ -140,7 +139,7 @@ func HandleListDatasetsRequest(jsonData []byte) {
// args = append(args, "--start", listRequest.Start)
// }

out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
return
Expand All @@ -164,7 +163,7 @@ func HandleListDatasetsRequest(jsonData []byte) {

v, err := json.Marshal(dsResponse)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand All @@ -183,7 +182,7 @@ func HandleListDsMembersRequest(jsonData []byte) {
// args = append(args, "--start", listRequest.Start)
// }

out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
return
Expand All @@ -208,7 +207,7 @@ func HandleListDsMembersRequest(jsonData []byte) {

v, err := json.Marshal(dsResponse)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand All @@ -223,7 +222,7 @@ func HandleRestoreDatasetRequest(jsonData []byte) {

args := []string{"./zowex", "data-set", "restore", dsRequest.Dataset}

out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
log.Println(string(out))
Expand All @@ -235,7 +234,7 @@ func HandleRestoreDatasetRequest(jsonData []byte) {
}
v, err := json.Marshal(dsResponse)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand Down
6 changes: 3 additions & 3 deletions native/golang/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"encoding/json"
"fmt"
"log"
"os/exec"
"os"
)

func HandleConsoleCommandRequest(jsonData []byte) {
Expand All @@ -25,7 +25,7 @@ func HandleConsoleCommandRequest(jsonData []byte) {
return
}
args := []string{"./zowexx", "console", "issue", request.Command, "--cn", request.Console}
out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
log.Println(string(out))
Expand All @@ -37,7 +37,7 @@ func HandleConsoleCommandRequest(jsonData []byte) {
}
v, err := json.Marshal(response)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand Down
22 changes: 11 additions & 11 deletions native/golang/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"encoding/json"
"fmt"
"log"
"os/exec"
"os"
"strconv"
"strings"
)
Expand All @@ -33,7 +33,7 @@ func HandleListJobsRequest(jsonData []byte) {
args = append(args, "--owner", listRequest.Owner)
}

out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
return
Expand All @@ -60,7 +60,7 @@ func HandleListJobsRequest(jsonData []byte) {

v, err := json.Marshal(jobsResponse)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand All @@ -76,7 +76,7 @@ func HandleListSpoolsRequest(jsonData []byte) {

args := []string{"./zowex", "job", "list-files", listRequest.JobId, "--rfc", "true"}

out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
return
Expand Down Expand Up @@ -108,7 +108,7 @@ func HandleListSpoolsRequest(jsonData []byte) {

v, err := json.Marshal(response)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand All @@ -127,7 +127,7 @@ func HandleReadSpoolRequest(jsonData []byte) {
if hasEncoding {
args = append(args, "--encoding", request.Encoding)
}
out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
return
Expand All @@ -143,7 +143,7 @@ func HandleReadSpoolRequest(jsonData []byte) {
}
v, err := json.Marshal(response)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand All @@ -158,7 +158,7 @@ func HandleGetJclRequest(jsonData []byte) {
}
// log.Println("GetJclRequest received:", ...)
args := []string{"./zowex", "job", "view-jcl", request.JobId}
out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
return
Expand All @@ -170,7 +170,7 @@ func HandleGetJclRequest(jsonData []byte) {
}
v, err := json.Marshal(response)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand All @@ -183,7 +183,7 @@ func HandleGetStatusRequest(jsonData []byte) {
return
}
args := []string{"./zowex", "job", "view-status", request.JobId, "--rfc", "true"}
out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
return
Expand All @@ -210,7 +210,7 @@ func HandleGetStatusRequest(jsonData []byte) {

v, err := json.Marshal(jobsResponse)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand Down
11 changes: 5 additions & 6 deletions native/golang/uss.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
)

Expand Down Expand Up @@ -65,7 +64,7 @@ func HandleListFilesRequest(jsonData []byte) {

v, err := json.Marshal(ussResponse)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand All @@ -84,7 +83,7 @@ func HandleReadFileRequest(jsonData []byte) {
if hasEncoding {
args = append(args, "--encoding", request.Encoding)
}
out, err := exec.Command(args[0], args[1:]...).Output()
out, err := buildExecCommand(args).Output()
if err != nil {
log.Println("Error executing command:", err)
return
Expand All @@ -99,7 +98,7 @@ func HandleReadFileRequest(jsonData []byte) {
}
v, err := json.Marshal(response)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand Down Expand Up @@ -133,7 +132,7 @@ func HandleWriteFileRequest(jsonData []byte) {
if len(request.Encoding) > 0 {
args = append(args, "--encoding", request.Encoding)
}
cmd := exec.Command(args[0], args[1:]...)
cmd := buildExecCommand(args)
stdin, err := cmd.StdinPipe()
if err != nil {
log.Println("Error opening stdin pipe:", err)
Expand Down Expand Up @@ -169,7 +168,7 @@ func HandleWriteFileRequest(jsonData []byte) {
}
v, err := json.Marshal(response)
if err != nil {
fmt.Println(err.Error())
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(string(v))
}
Expand Down

0 comments on commit dcfcdbe

Please sign in to comment.