Link to home
Start Free TrialLog in
Avatar of Rick Becker
Rick BeckerFlag for United States of America

asked on

SHELL Escape Command produces Error from Within Code but Not From Command Prompt

Ok I have a Simple ( maybe not so simple ) SHELL escape that fails when executing from within my code but runs fine when executed from a Command Prompt. Here is the command that I am trying to execute:

 Shell("curl ""https://api.discogs.com/database/search?q=" + SearchString + """ -H " + """Authorization: Discogs token=" + MyToken + """ > C:\Downloads\CurlOutput.txt 2>&1")

Open in new window


I get a system error telling that the file NOT FOUND... I am redirecting the output TO a file NOT reading FROM a file???

Here is the expanded version of that string.. I can change my TOKEN at any time so it is ok...

curl "https://api.discogs.com/database/search?q=0075992511025" -H "Authorization: Discogs token=xyz" > C:\Downloads\CurlOutput.txt 2>&1

Open in new window


I am using VS 2017 and I am coding in VB.NET on a Windows 10 Machine

Thanks in advance
Rick
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rick Becker

ASKER

Hi Saige,

Well I have been trying to use WEBCLIENT but I was also getting nowhere with that. I had tried 'POSTing' as well and also no luck...

This work Right Away so I thank you very much.. I will use your solution but I am still confused as to why the SHELL command does not work. That was a Single line solution vs a multi-line solution... The Great news is that one works while the other does not.... hehe

Thanks again
Rick
For what it's worth, chances are that Shell didn't work because it couldn't find the curl executable. Since you are not specifying a path to it, you would need the curl.exe file to be in the same folder as your application, or within the common system path.
WOW Gonzo You Are RIGHT... How can I give you credit for that.. I am so pressed for time that I grabbed the first solution that would work...

Man I'm sorry that I was so quick to jump...

Rick
Well, personally I would recommend it_saige's answer anyway. It's more efficient than invoking the shell to run cURL, AND more importantly, it eliminates a 3rd party dependency, which is always a good thing. Don't get me wrong - I love cURL as much as the next person (and I use the curl plugin in PHP all the time), but .NET framework has all the tools that you need already. There's not much sense in ignoring what you have immediately available.

I only commented because there are some other similar situations where it's helpful to call some kind of command-line application (where .NET doesn't already have the functionality).
Ok thanks for the advice... I know that the internet allows for anonymity and anybody can say and be anything they want I just want to say thanks because I can use all the 'Extra' help that can get because you see I am 70 and most of my knowledge is 'OLD' so it takes me awhile  learn and understand some of these newer languages... and it 'Bugs'  me when something worked before and now doesn't...

Hehe
If you hover your mouse cursor over the profile photo, you'll see a popup that indicates the expert's overall level and their experience level within a particular topic zone. So for example, if you hover over it_saige's photo, you can see that the overall level is 38 (which is decently high), and that he/she has a fairly high level of experience with VB.Net (level 21 right now). That info can sometimes help you establish some confidence in the answers people give.

Granted, nobody's perfect, and even experienced people are capable of giving bad answers, but the higher the level, the lower the risk of getting a bad answer from that person.

Meanwhile, my overall level is 40, but I haven't really participated a lot in VB.Net questions because I'm usually participating more on C# .NET and PHP questions, but I'm pretty familiar with the .NET framework in general.

In any event, these are just little tips to help you when asking questions.
Thanks Gonzo that is all great advice and information. I appreciate it very much....

I wonder if it would be out of line for you to take a look at my 1 outstanding question ..."Converting VB6 to VB.NET - File upload via  MSXML2.ServerXMLHTTP results in error in VB.NET" I am really stumped and I have tried many variations with no 'Additional' luck... meaning that I can get further with it but still a failure...

Anyway thanks for your interest and help

Rick
Thanks Qlemo,

OK that sounds great... and no I did not know about the change ... and yes I have not been on EE for quite some time now, but I have been "Dragged Out Of Moth Balls".... LOL