I try to set a variable for a javascript function with my cgi script hosted on the local IIS(Win7):
cgi:
cout<<"Content-type: text/javascript\r\n\r\n";
cout<<"var value=2;";
javascript:
<script type="text/javascript" src="./cgi-bin/value.exe"></script>
<script type="text/javascript">
<!--
document.write('The number is: ' + value);
-->
</script>
But when i open the html file with the js-code document.write does nothing. And when i analyse the page with firebug a lot of weird characters inside the js-tag and somewhere in the middle of these characters there is my output: “var value=2”.
Has anybody an idea what is going on?
Any help would be greatly appreciated!
EDIT: here a snippet from what firebug tells me is between the script tags:
MZ�������ÿÿ��¸�������@�����
)��")��4)��F)��\)��p)��z)��)��)��)��¬)��Æ)
��Ø)��)��ô(��Ê(��¼ (��°(��¤(��(��(��(�
(��l(��^(��<(��à(����������@���������È@�û��
������bad allocation��Content-type: text/javascript
���var NumberOfFiles = 2;
?�������������0���������������� ��H���
X@��V�������<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b">
</assemblyIdentity>
</dependentAssembly>
</dependency>
/assembly>PAPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDING
XXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADD���0�������
Can anyone tell where this output is coming from?
Seems to just fine here. Naturally, you gotta run it from localhost (or some other server)
testCgi.html
cgiBinNum.cpp
Output:
Yeah, the ‘MZ’ gives it away instantly – Mark Zbikowski.
Basically, it’s actually serving up the exe file itself, not just the result of it.
If you open the file in a hex-editor, it will look remarkably similar.
When you say, that’s ‘pretty-much’ what you’ve got, the devil is always in the details.
Got any more of them?
I’ve 2 suggestions –
(1) provide the smallest full source that replicates your problem, as I have done
(2) change the file extension to .cgi and alter the javascript to reflect this. (You should also get into the habit of adding another build-target to the project and set it’s output folder to your cgi-bin folder, also the extension to cgi, rather than exe) This shouldn’t make a difference to this problem, but it is better in general not to have easily executable files in that folder – easily, as in you can double-click them and they will run, you can always run from the command line if you use a full path, as apache does.
Ahhh! Just realized you’re using IIS – I think you find that it’s that b@stard of a thing that’s messing up your output. Probably makes point (1) moot – It’s sounding more likely to me that it will be a IIS setting – though it could also be serving the contents of the file, rather than the output – simply based on it’s extension. Give it a try!