blob: 392ccfb85db0fa308e81321d8efb761883ee3bac [file] [log] [blame]
mccd7e9502019-12-16 22:04:13 +00001// Copyright 2018-present Open Networking Foundation
Dinesh Belwalkar6c0bc752020-04-24 23:47:53 +00002// Copyright 2018-present Edgecore Networks Corporation
mccd7e9502019-12-16 22:04:13 +00003//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// 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
16package main
17
18import "net"
19import "fmt"
20import "bufio"
21import "os"
22import "strings"
Scott Bakerbdb962b2020-04-03 10:53:36 -070023import "log"
mccd7e9502019-12-16 22:04:13 +000024
25func main() {
Scott Bakerbdb962b2020-04-03 10:53:36 -070026 if len(os.Args) <= 1 {
27 log.Printf("Syntax: ./dm <arguments>")
28 os.Exit(-1)
29 }
30
mccd7e9502019-12-16 22:04:13 +000031 // connect to this socket
mccd7e9502019-12-16 22:04:13 +000032 cmdstr := strings.Join(os.Args[1:], " ")
Scott Bakerbdb962b2020-04-03 10:53:36 -070033 conn, err := net.Dial("tcp", "127.0.0.1:9999")
34 if err != nil {
35 log.Printf("Error opening connection: %v", err)
36 os.Exit(-1)
37 }
38
mccd7e9502019-12-16 22:04:13 +000039 // send to socket
Dinesh Belwalkara6ba07d2020-01-10 23:22:34 +000040 fmt.Fprintf(conn, cmdstr+"\n")
mccd7e9502019-12-16 22:04:13 +000041
42 // listen for reply
Scott Bakerbdb962b2020-04-03 10:53:36 -070043 message, err := bufio.NewReader(conn).ReadString(';')
44 if err != nil {
45 log.Printf("Error reading result: %v", err)
46 os.Exit(-1)
47 }
48
mccd7e9502019-12-16 22:04:13 +000049 message = strings.TrimSuffix(message, ";")
50 fmt.Print(message)
51}