github.com/coveo/gotemplate@v2.7.7+incompatible/docs/doc_test/os-commands.razor (about) 1 {% include navigation.html %} 2 {% raw %} 3 4 # OS commands 5 6 It is possible to run OS commands using the following go template functions: 7 8 * `exec` returns the result of a shell command as structured data. 9 * `run` returns the result of a shell command as a string. 10 11 ## exec 12 13 ### Razor 14 ``` 15 {{- $example := exec "printf 'SomeData: test2\nSomeData2: test3'" }} 16 First result: {{ $example.SomeData }} 17 Second result: {{ $example.SomeData2 }} 18 {{ $example }} 19 20 {{- $example2 := exec "printf 'Test'" }} 21 Should be `string`: {{ typeOf $example2 }} 22 {{ $example2 }} 23 ``` 24 25 ### Gotemplate 26 ``` 27 {{- $example := exec "printf 'SomeData: test2\nSomeData2: test3'" }} 28 First result: {{ $example.SomeData }} 29 Second result: {{ $example.SomeData2 }} 30 {{ $example }} 31 32 {{- $example2 := exec "printf 'Test'" }} 33 Should be `string`: {{ typeOf $example2 }} 34 {{ $example2 }} 35 ``` 36 37 ### Result 38 ``` 39 First result: test2 40 Second result: test3 41 SomeData: test2 42 SomeData2: test3 43 44 Should be `string`: string 45 Test 46 ``` 47 48 ## run 49 50 ### Razor 51 ``` 52 {{- $example := run "printf 'SomeData: test2\nSomeData2: test3'" }} 53 Should be `string`: {{ typeOf $example }} 54 {{ $example }} 55 ``` 56 57 ### Gotemplate 58 ``` 59 {{- $example := run "printf 'SomeData: test2\nSomeData2: test3'" }} 60 Should be `string`: {{ typeOf $example }} 61 {{ $example }} 62 ``` 63 64 ### Result 65 ``` 66 Should be `string`: string 67 SomeData: test2 68 SomeData2: test3 69 ``` 70 71 72 {% endraw %}