File Name: Get-Radiation.ps1
#Call of this script should be as follows:
#Get-Radiation -RemoteHost "10.1.2.3" -OutputPath "\\WB-SYSTEM\RADCOMM\output.txt"
Param (
[Parameter(ValueFromPipeline=$true)]
[string]$RemoteHost = "10.1.2.3",
[string]$Port = "9000",
[int]$WaitTime = 1000,
[string]$OutputPath = "\\user-pc\RADCOMM\output.txt"
)
$Socket = New-Object System.Net.Sockets.TcpClient($RemoteHost, $Port)
If ($Socket)
{ $Stream = $Socket.GetStream()
$Writer = New-Object System.IO.StreamWriter($Stream)
$Buffer = New-Object System.Byte[] 1024
$Encoding = New-Object System.Text.AsciiEncoding
$Writer.WriteLine("RC0101")
$Writer.Flush()
Start-Sleep -Milliseconds (1000)
$Result = ""
#Save all the results
While($Stream.DataAvailable)
{ $Read = $Stream.Read($Buffer, 0, 1024)
$Result += ($Encoding.GetString($Buffer, 0, $Read))
}
}
Else
{ $Result = "Unable to connect to host: $($RemoteHost):$Port"
}
#Done, now save the results to a file
$Result | Out-File $OutputPath
You have to basically call the Function Module SXPG_COMMAND_EXECUTE with two parameters namely, the IP Address of Radiation System and the output path where the output will be saved.
CONCATENATE '-RemoteHost "' wa_zsrsw-radip
'" -OutputPath "\\' wa_zsrsw-term '\D$\RADCOMM\output.txt"'
INTO v_param.
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = 'ZGET_RADIATION' "v_oscmd
additional_parameters = v_param
operatingsystem = sy-opsys
IMPORTING
status = v_status
exitcode = v_exitcode
TABLES
exec_protocol = i_cmdresult
EXCEPTIONS
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
OTHERS = 15.
IF sy-subrc <> 0.
v_ossysubrc = sy-subrc.
CASE sy-subrc.
WHEN 1. v_errtxt = 'ATG:You do not have permission to get Radiation Data'.
WHEN 2. CONCATENATE 'ATG:Command' v_oscmd 'Not Found' INTO v_errtxt SEPARATED BY ''.
WHEN OTHERS. CONCATENATE 'ATG:Error in calling command' v_oscmd INTO v_errtxt SEPARATED BY ''.
ENDCASE.
MESSAGE v_errtxt TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |