major4579 Posted January 16, 2023 Author Share Posted January 16, 2023 (edited) I've been trying to capture the output of the nccs.php file using Curl, but I cannot get it to work correctly. First here's my Autoit code. (Note: I have double checked that $sDate is correctly formatted): ;Set path to Curl $sPath = EnvGet ('PATH') $sPath = $sPath & ';C:\utility\Curl\bin\' EnvSet ('PATH', $sPath) ; Run Curl $cmd = 'curl.exe -u username:password https://instanthousecall.com/x/admin/nccs.php?startDate=$sDate$' $iPID = Run('$cmd$', "C:\utility\Curl\bin\", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $sHTML = StdoutRead($iPID) MsgBox (262144, '', $sHTML) Here's the display of MsgBox showing the @sHTML varaible on the last line: Now if I open a Command Window and change to the directory where Curl.exe is, and then run the exact same command line this is what I get: Note the text after "/head" in the command window. That is the text that I need to see in the Autoit script. I feel like I'm very close, but I can't figure out why it only works in the command window. Any help would be greatly appreciated! Thanks, John Edited January 16, 2023 by major4579 Link to comment Share on other sites More sharing options...
Danp2 Posted January 17, 2023 Share Posted January 17, 2023 From the help file -- Quote StdoutRead() does not block, it will return immediately. In order to get all data, it must be called in a loop. Have you tried reading the output in a loop? -- Local $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf WEnd MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted January 17, 2023 Share Posted January 17, 2023 Hi @major4579, in case the suggested way of @Danp2 doesn't work for you, you could also work-around it by transfer the cURL response to a file and then read this [...] proceed it. I know this would not very elegant, but it should work at least. Something like this: $cmd = 'curl.exe -u username:password https://instanthousecall.com/x/admin/nccs.php?startDate=$sDate$' $filePath = @ScriptDir & '\response.txt' $iPID = Run('$cmd$ > "' & $filePath & '"', "C:\utility\Curl\bin\", @SW_HIDE, $STDOUT_CHILD) Best regards Sven Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
major4579 Posted January 17, 2023 Author Share Posted January 17, 2023 @Danp2 I tried that but it did not work any differently then "ProcessWaitClose($iPID)" @SOLVE-SMART I was thinking of trying that - I will give it a go and report back later today or tomorrow. Have to do some real work! Link to comment Share on other sites More sharing options...
Danp2 Posted January 17, 2023 Share Posted January 17, 2023 45 minutes ago, major4579 said: I tried that but it did not work any differently then "ProcessWaitClose($iPID)" To clarify, my suggestion was to use the loop following the ProcessWaitClose, not as a replacement for it. Do it this way will eliminate the chance that only a portion of the output is captured. SOLVE-SMART 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
major4579 Posted January 17, 2023 Author Share Posted January 17, 2023 @SOLVE-SMART It's doing the same thing. If I run C:\utility\Curl\bin\curl.exe -u username:passwordhttps://instanthousecall.com/x/admin/nccs.php?startDate=2023-01-11 > D:\IHC.txt In a command window (does not matter what location I'm running it from) i works fine D:\IHC.txt contains what I need. If I run the exact same line in Autoit, D:\IHC.txt never even gets created. $cmd = 'C:\utility\Curl\bin\curl.exe -u username:password https://instanthousecall.com/x/admin/nccs.php?startDate=2023-01-11 > D:\IHC.txt' $iPID = Run('$cmd$', 'C:\utility\Curl\bin', @SW_HIDE) But if I run $cmd = 'C:\utility\Curl\bin\curl.exe -u username:password https://instanthousecall.com/x/admin/nccs.php?startDate=2023-01-11 > D:\IHC.txt' $iPID = Run($cmd, 'C:\utility\Curl\bin', @SW_HIDE) It does work. For what it's worth I do have "Opt ("ExpandVarStrings", 1) " at the beginning of my autoit file. Link to comment Share on other sites More sharing options...
major4579 Posted January 17, 2023 Author Share Posted January 17, 2023 @Danp2 I'll give that a try when I return - I have to run out. Thanks, John Link to comment Share on other sites More sharing options...
Danp2 Posted January 17, 2023 Share Posted January 17, 2023 @major4579A few suggestions to hopefully get things moving in the right direction -- Remove the @sw_hide until you get things working correctly Check the value of $iPID and @error following the Run() Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
major4579 Posted January 17, 2023 Author Share Posted January 17, 2023 Finally, This code works: $cmd = 'C:\utility\Curl\bin\curl.exe -u username:password https://instanthousecall.com/x/admin/nccs.php?startDate=' & $sDate $iPID = Run($cmd, 'C:\utility\Curl\bin', @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $sHTML = StdoutRead($iPID) Previously in the $cmd line I had $sDate in the end of the string as $sDate$ and in the Run command I had '$cmd$'. But for some reason I haven't figured out the Opt ("ExpandVarStrings", 1) had stopped working . Interestingly it works everywhere else as far as I can see. In fact if I add MsgBox (262144, '', '>>>$sHTML$<<<') after the last line above that works correctly! Go figure. Thanks to both Danp2 and SOLVE-SMART for sticking with me while we figured this out. BTW, who should get the credit? John Link to comment Share on other sites More sharing options...
Danp2 Posted January 17, 2023 Share Posted January 17, 2023 @major4579Glad you got it working. I wonder if there is an issue with "double expansion" with the contents of $cmd? 🤔 You should give credit to @mikellsince using curl was his idea. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted January 17, 2023 Share Posted January 17, 2023 (edited) 30 minutes ago, major4579 said: Finally, This code works [...] Nice 😀 . 7 minutes ago, Danp2 said: [...] You should give credit to @mikellsince using curl was his idea. Agreed 👍 . A last tryout could be the usage of ShellExecute() instead of Run(). Just to ensure the bahavior is the same or not. Best regards Sven Edited January 17, 2023 by SOLVE-SMART Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
major4579 Posted January 18, 2023 Author Share Posted January 18, 2023 @SOLVE-SMART I tried ShellExecute with the output of curl directed to a file (since ShellExecute doesn't support $STDOUT_CHILD) and it didn't work any better. @Danp2 I did try the loop after the ProcessWaitClose and it still didn't work. Thanks again to both of you! I give @mikell the credit. -John Link to comment Share on other sites More sharing options...
mikell Posted January 18, 2023 Share Posted January 18, 2023 1 hour ago, major4579 said: I give @mikell the credit. Thanks. I was away for some days and couldn't participate... Glad I could help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now