Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use RunConsole2 to Execute Long Commands
#1
I want to use `RunConsole2` to execute a `curl` command. The command includes a content parameter that must be a file encoded in base64. This makes the command string very long. When I try to execute it, I get the error:
**"The file name or extension is too long."**
Is there any solution for this? Thanks in advance.
 The command contains a token, so using an external file is not secure.


Macro Macro5
Code:
Copy      Help
str cl=
;curl -s -L -X PUT -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ghp_" -H "X-GitHub-Api-Version: 2022-11-28" -H "Content-Type: application/json" https://api.github.com/repos/xxxx/F2/contents/Temp/video.mp4 -d "{     \"message\": \"Upload: Temp/video.mp4\",     \"content\": \"AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAu54ptZGF0AAACrwYF//+r3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDE2NCByMzA5NCBiZmM4N2I3IC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENvcHlsZWZ0IDIwMDMtMjAyMiAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9wdGlvbnM6IGNhYmFjPTEgcmVmPTMgZGVibG9jaz0xOjA6MCBhbmFseXNlPTB4MzoweDExMyBtZT1oZXggc3VibWU9NyBwc3k9MSBwc3lfcmQ9MS4wMDowLjAwIG1peGVkX3JlZj0xIG1lX3JhbmdlPTE2IGNocm9tYV9tZT0xIHRyZWxsaXM9MSA4eDhkY3Q9MSBjcW09MCBkZWFkem9uZT0yMSwxMSBmYXN0X3Bza2lwPTEgY2hyb21hX3FwX29mZnNldD0tMiB0aHJlYWRzPTI0IGxvb2thaGVhZF90aHJlYWRzPTQgc2xpY2VkX3RocmVhZHM9MCBucj0wIGRlY2ltYXRlPTEgaW50ZXJsYWNlZD0wIGJsdXJheV9jb21wYXQ9MCBjb25zdHJhaW5lZF9pbnRyYT0wIGJmcmFtZXM9MyBiX3B5cmFtaWQ9MiBiX2FkYXB0PTEgYl9iaWFzPTAgZGlyZWN0PTEgd2VpZ2h0Yj0xIG9wZW5fZ29wPTAgd2VpZ2h0cD0yIGtleWludD0yNTAga2V5aW50X21pbj0yNSBzY2VuZWN1dD00MCBpbnRyYV9yZWZyZXNoPTAgcmNfbG9va2FoZWFkPTQwIHJjPWNyZiBtYnRyZWU9MSBjcmY9MjMuMCBxY29tcD0wLjYwIHFwbWluPTAgcXBtYXg9NjkgcXBzdGVwPTQgaXBfcmF0aW89MS40MCBhcT0xOjEuMDAAgAABAl5liIQAn4fpJG5JPnZ2AhrfA+pg8WDtW2Hocee0BI8peaISS3EjdGEAAAABAAAAAExhdmY1OS4yMi4xMDA=\" }"

RunConsole2(cl _s)
out _s

chatgpt:

1. File: data.json
{
  "message": "Upload: Temp/video.mp4",
  "content": "AAAAIGZ0eXBp..."
}
2. cmd:
curl -s -L -X PUT ^
  -H "Accept: application/vnd.github+json" ^
  -H "Authorization: Bearer ghp_Token" ^
  -H "X-GitHub-Api-Version: 2022-11-28" ^
  -H "Content-Type: application/json" ^
  https://api.github.com/repos/xxx/F2/cont.../video.mp4 ^
  --data "@data.json"
#2
Curl should support an arguments file, like curl --config file.txt. But you say it's unsafe. Let the script delete the file.
#3
Thanks for your help.
I set the token in a variable named cl , and placed the base64 content of the file to be uploaded in an external data.json file.
This seems to have solved my problem, and uploading large files has also been successfully tested.
 
Code:
Copy      Help
str cl=
F
;curl -s -L -X PUT
;-H "Accept: application/vnd.github+json"
;-H "Authorization: Bearer {token}"
;-H "X-GitHub-Api-Version: 2022-11-28"
;-H "Content-Type: application/json"
;https://api.github.com/repos/{owner}/{repo}/contents/{path}
;--data "@data.json"
#4
Quote:Let the script delete the file.

I have a related question:
How to use QM code to always delete a specified file—which contains some sensitive content—in all error or exception scenarios?  Huh
#5
Macro Macro3494
Code:
Copy      Help
sub.TempFileExample


#sub TempFileExample

str data="data"
__TempFile f.Init("" "" "" data)

out f.m_file

;auto-deleted here, on normal return or exception, but not if this process or thread terminated without possibility to run destructors
#6
Thanks for your help.
I’ve used that function before, and using it here is indeed a great idea.  Idea


Forum Jump:


Users browsing this thread: 2 Guest(s)