通过流输入输出 - Longchar 输入
Input-output through stream - Longchar Input
如能提供以下帮助,我们将不胜感激。
我正在尝试运行一个OS-command in progress using input-output through.
案例:
Run command: "echo 'this is a long string'"
Capture output: "'this is a long string'"
问题是:
- 我输入的字符串可能超过了字符限制
- 当 运行ning 直接使用
through "program"
或 through value("expression")
输入是 t运行 约 2500-3000 个字符。
- 整个操作运行可以使用文件,但要避免 IO 和管理。
- 无法将我的数据附加到 OS-命令(利用
put
或 export
)
谁能推荐一种执行命令行的方法,附加数据超过 35,000 个字符?
这是我尝试过的方法:(以及许多排列组合)
define variable cLongMsg as character no-undo.
define variable iLoop as integer no-undo.
define variable lcResp as longchar no-undo.
define variable cFileLine as character no-undo.
define stream logStream.
input-output stream logStream through "curl".
/* execute curl -- attach data using put */
put stream logStream "http://whosebug.com".
put stream logStream "-d 'key=long_data"
put stream logStream "&value=more_long_data'"
put stream logStream CONTROL NULL(0).
output close.
read_loop:
repeat:
import stream logStream unformatted cFileLine.
assign lcResp = lcResp + cFileLine.
end.
input close.
input-output close.
message "[OUT] " + string(lcResp) view-as alert-box.
目前使用的方案:
进度文件
function CURL_long returns longchar private (
input cInput as longchar).
def var cUnixCMD as longchar no-undo.
def var cDataPart as char no-undo.
def var cData as longchar no-undo.
def var cResultChunk as char no-undo.
def var iResultChunkMax as inte init 30000 no-undo.
def var iUsedChunkMax as inte no-undo.
def var iResultPos as inte no-undo.
fix-codepage(cData) = "UTF-8".
assign cUnixCMD = "curl " + cInput + " | fold -c30000".
input-output stream CURL_CMD through "input_buffer.sh".
/* set the result position */
assign iResultPos = 0.
ResultLoop:
repeat:
if iResultPos + iUsedChunkMax > length(cUnixCMD) then
do:
assign cResultChunk = substring(cUnixCMD, iResultPos + 1).
put stream CURL_CMD unformatted cResultChunk skip.
leave ResultLoop.
end.
/* set the current chunk of the result */
assign cResultChunk = substring(cUnixCMD, iResultPos + 1, iResultChunkMax)
iUsedChunkMax = iResultChunkMax.
put stream CURL_CMD unformatted cResultChunk skip.
assign iResultPos = iResultPos + iUsedChunkMax.
end. /* ResultLoop: repeat: */
output stream CURL_CMD close.
read_loop:
repeat:
import stream CURL_CMD unformatted cDataPart.
if cDataPart <> "" then assign cData = cData + cDataPart.
else leave.
end.
return cData.
end function.
Bash 文件
#!/bin/bash
myCMD=""
while IFS= read line
do
myCMD+=$line
done
eval $myCMD
exit
您可以使用-inp 启动参数来解决这个问题。更多信息在这里:
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dpspr/input-characters-(-inp).html
您的方向是正确的,只是存在一些小的语法问题。
这对我有用:
define variable lcResp as longchar no-undo.
define variable cFileLine as character no-undo.
define stream logStream.
input stream logStream through "curl https://whosebug.com".
read_loop:
repeat:
import stream logStream unformatted cFileLine.
assign lcResp = lcResp + cFileLine + "~n".
end.
input stream logStream close.
message "[OUT] " length( lcResp ) view-as alert-box.
COPY-LOB lcResp to file "zzz".
MESSAGE 语句在超过大约 30,000 个字符时无法输出 lcResp。我用 length( lcResp ) 来表明我得到了数据。
MESSAGE、PUT 或 EXPORT 等输出语句不适用于 longchar 数据。您需要使用 COPY-LOB 直接读取或写入 longchar。
另外——小心处理换行符或缺少换行符。未以换行符终止的 INPUT 将在 REPEAT 循环中被 IMPORT 丢失。我通常使用更像这样的东西来避免这种情况:
define variable lcResp as longchar no-undo.
define variable cFileLine as character no-undo.
define stream logStream.
input stream logStream through "curl https://whosebug.com".
read_loop: do while true:
cFileLine = ?.
do on endkey undo, leave
on error undo, leave:
import stream logStream unformatted cFileLine.
end.
if cFileLine = ? then
leave read_loop.
else
lcResp = lcResp + cFileLine + chr(13) + chr(10).
end.
input stream logStream close.
message "[OUT] " length( lcResp ) view-as alert-box.
COPY-LOB lcResp to file "zzz".
如果您的换行符需要特定格式,"chr(13) + chr(10)" 业务可能很重要。
如能提供以下帮助,我们将不胜感激。
我正在尝试运行一个OS-command in progress using input-output through.
案例:
Run command: "echo 'this is a long string'"
Capture output: "'this is a long string'"
问题是:
- 我输入的字符串可能超过了字符限制
- 当 运行ning 直接使用
through "program"
或through value("expression")
输入是 t运行 约 2500-3000 个字符。 - 整个操作运行可以使用文件,但要避免 IO 和管理。
- 无法将我的数据附加到 OS-命令(利用
put
或export
)
谁能推荐一种执行命令行的方法,附加数据超过 35,000 个字符?
这是我尝试过的方法:(以及许多排列组合)
define variable cLongMsg as character no-undo.
define variable iLoop as integer no-undo.
define variable lcResp as longchar no-undo.
define variable cFileLine as character no-undo.
define stream logStream.
input-output stream logStream through "curl".
/* execute curl -- attach data using put */
put stream logStream "http://whosebug.com".
put stream logStream "-d 'key=long_data"
put stream logStream "&value=more_long_data'"
put stream logStream CONTROL NULL(0).
output close.
read_loop:
repeat:
import stream logStream unformatted cFileLine.
assign lcResp = lcResp + cFileLine.
end.
input close.
input-output close.
message "[OUT] " + string(lcResp) view-as alert-box.
目前使用的方案:
进度文件
function CURL_long returns longchar private (
input cInput as longchar).
def var cUnixCMD as longchar no-undo.
def var cDataPart as char no-undo.
def var cData as longchar no-undo.
def var cResultChunk as char no-undo.
def var iResultChunkMax as inte init 30000 no-undo.
def var iUsedChunkMax as inte no-undo.
def var iResultPos as inte no-undo.
fix-codepage(cData) = "UTF-8".
assign cUnixCMD = "curl " + cInput + " | fold -c30000".
input-output stream CURL_CMD through "input_buffer.sh".
/* set the result position */
assign iResultPos = 0.
ResultLoop:
repeat:
if iResultPos + iUsedChunkMax > length(cUnixCMD) then
do:
assign cResultChunk = substring(cUnixCMD, iResultPos + 1).
put stream CURL_CMD unformatted cResultChunk skip.
leave ResultLoop.
end.
/* set the current chunk of the result */
assign cResultChunk = substring(cUnixCMD, iResultPos + 1, iResultChunkMax)
iUsedChunkMax = iResultChunkMax.
put stream CURL_CMD unformatted cResultChunk skip.
assign iResultPos = iResultPos + iUsedChunkMax.
end. /* ResultLoop: repeat: */
output stream CURL_CMD close.
read_loop:
repeat:
import stream CURL_CMD unformatted cDataPart.
if cDataPart <> "" then assign cData = cData + cDataPart.
else leave.
end.
return cData.
end function.
Bash 文件
#!/bin/bash
myCMD=""
while IFS= read line
do
myCMD+=$line
done
eval $myCMD
exit
您可以使用-inp 启动参数来解决这个问题。更多信息在这里: https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dpspr/input-characters-(-inp).html
您的方向是正确的,只是存在一些小的语法问题。
这对我有用:
define variable lcResp as longchar no-undo.
define variable cFileLine as character no-undo.
define stream logStream.
input stream logStream through "curl https://whosebug.com".
read_loop:
repeat:
import stream logStream unformatted cFileLine.
assign lcResp = lcResp + cFileLine + "~n".
end.
input stream logStream close.
message "[OUT] " length( lcResp ) view-as alert-box.
COPY-LOB lcResp to file "zzz".
MESSAGE 语句在超过大约 30,000 个字符时无法输出 lcResp。我用 length( lcResp ) 来表明我得到了数据。
MESSAGE、PUT 或 EXPORT 等输出语句不适用于 longchar 数据。您需要使用 COPY-LOB 直接读取或写入 longchar。
另外——小心处理换行符或缺少换行符。未以换行符终止的 INPUT 将在 REPEAT 循环中被 IMPORT 丢失。我通常使用更像这样的东西来避免这种情况:
define variable lcResp as longchar no-undo.
define variable cFileLine as character no-undo.
define stream logStream.
input stream logStream through "curl https://whosebug.com".
read_loop: do while true:
cFileLine = ?.
do on endkey undo, leave
on error undo, leave:
import stream logStream unformatted cFileLine.
end.
if cFileLine = ? then
leave read_loop.
else
lcResp = lcResp + cFileLine + chr(13) + chr(10).
end.
input stream logStream close.
message "[OUT] " length( lcResp ) view-as alert-box.
COPY-LOB lcResp to file "zzz".
如果您的换行符需要特定格式,"chr(13) + chr(10)" 业务可能很重要。