Different behaviour of Shell Execute vs batch

I am currently doing a project where I am learning how to get data from a public endpoint API (specifically binance) with a view to eventually being able to autotrade.

The method I have chosen is to create a folder, and in that folder create a html file, and place a string input into that file.
It works and I am getting the data I want from Binance API.

fmkdir("C:\\Program Files\\AmiBroker\\Export\\");
path= "C:\\Program Files\\AmiBroker\\Export\\" + Name() + ".html";
fh = fopen(path,"w");



if(fh)
{
filecontent = StrFormat(
	"<html>"
	+"\n<body>"
	+"\n</body>"
	+"\n<script>"

	+"\nvar burl ='https://api1.binance.com';"
    
	+"\nvar query = '/api/v3/klines';"
    
	+"\nquery += '?symbol="
	+ Name() + "&interval=1d&limit=20';"
    
	+"\nvar url = burl + query;"
    
	+"\nvar ourRequest = new XMLHttpRequest();"

	+"\nourRequest.open('GET',url,true);"
	+"\nourRequest.onload = function(){"
	+	"\nconsole.log(ourRequest.responseText);"
	+"\n}"
	+"\nourRequest.send();"
    
	+"\n</script>"
	+"\n</html>;");
	
	fputs(filecontent,fh);
	
	fclose(fh);
	
	ShellExecute(path,"","",1);
	
}

However, I needed to click through some menus to open the developer console, which was cumbersome.
After an internet trawl, I found that by entering "C:\Program Files\Google\Chrome\Application\chrome.exe" -auto-open-devtools-for-tabs , into the command prompt, I get a browser launched into the developer console, but still, this relies on me first manually doing this.

So then I started playing with batch, and if I create a batch;
Action: Execute and Wait,
Parameter/File: "C:\Program Files\Google\Chrome\Application\chrome.exe" -auto-open-devtools-for-tabs

and run it, again, I get the developer tab in Chrome. Great.
So next, I saved the command as a batch file and I used this code...

ShellExecute("runbatch","C:\\Program Files\\AmiBroker\\Scripts\\Batch\\Load Chrome.abb","",1);

That works, when it is executed by itself. I get a single browser tab, opened in the developer consoler.

However, this still does not solve my problem. When I run it combined with the code write the html file for the binance API, I don't get what it is I am looking for....

ShellExecute("runbatch","C:\\Program Files\\AmiBroker\\Scripts\\Batch\\Load Chrome.abb","",1);

fmkdir("C:\\Program Files\\AmiBroker\\Export\\");
path= "C:\\Program Files\\AmiBroker\\Export\\" + Name() + ".html";
fh = fopen(path,"w");



if(fh)
{
filecontent = StrFormat(
	"<html>"
	+"\n<body>"
	+"\n</body>"
	+"\n<script>"

	+"\nvar burl ='https://api1.binance.com';"
    
	+"\nvar query = '/api/v3/klines';"
    
	+"\nquery += '?symbol="
	+ Name() + "&interval=1d&limit=20';"
    
	+"\nvar url = burl + query;"
    
	+"\nvar ourRequest = new XMLHttpRequest();"

	+"\nourRequest.open('GET',url,true);"
	+"\nourRequest.onload = function(){"
	+	"\nconsole.log(ourRequest.responseText);"
	+"\n}"
	+"\nourRequest.send();"
    
	+"\n</script>"
	+"\n</html>;");
	
	fputs(filecontent,fh);
	
	fclose(fh);
	
	ShellExecute(path,"","",1);
	
}

I end up with 2 browsers, neither of which are opened in the console.
Any idea, critique or suggested alternative approaches, would be hugely welcome.

Thanks so much.

Spandy.

In windows CMD, the following works

start chrome -auto-open-devtools-for-tabs c:\path\to\htmlfile.html

so you can send 2 arguments, the devtools option as well as the full path of html file.

If you are combining them, first write to file and pass the file to chrome in a single ShellExecute().

You are using 2 separate ShellExecute() calls which wont do the job.

In AB, this works. Space separates the two arguments.

ShellExecute("chrome","-auto-open-devtools-for-tabs c:\\path\\to\\htmlfile.html","", 1);

If you have spaces in path, make sure to escape properly.
Also in my case, once Google chrome is running, the subsequent calls open new tabs in the same Chrome instance.

1 Like

Awesome!! Thanks so much.

I had to replace each space with %20 and use forward slashes. I set up a new array for that job and it works

So;

path= "C:\\Program Files\\AmiBroker\\Export\\" + Name() + ".html";
path2= "file:///C:/Program%20Files/AmiBroker/Export/"+ Name() + ".html";

and then on executuion I had to manually add a space using " ", which ended up looking like this...

ShellExecute("chrome","-auto-open-devtools-for-tabs"+" "+path2,"",1);

Thanks so much!!!

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.