When I run javascript script file in windows command line environment, and there is a free text coming after my code. How can I stop javascript interpreter to run into it?
For example:
var fso = new ActiveXObject("Scripting.FileSystemObject");
delete fso;
exit(); // some kind of WORKING exit command
Hungry lazy frog ate a big brown fox.
There is nothing you can do to stop the interpreter before it the compiler sees a particular line because the whole Javascript source file is first compiled to bytecode and it is the bytecode that is interpreted not your source code.
What you could do (though it would still be messy) would be to put some free text in a comment at the end of the file. Then you could open the source file and read it from the rest of the code. It still can't be completely free text though as it would have to be a valid comment
/*
whatever text you want provided it doesn't contain * followed immediately by /
*/
Much better is simply to admit defeat and store any data you need in a separate file.
If you surround that with quotes it will be interpreted/compiled but will have no effect eg
var fso = new ActiveXObject("Scripting.FileSystemObject");
delete fso;
exit(); // some kind of WORKING exit command
"Hungry lazy frog ate a big brown fox.";
Even if you did exit, you'd still have a problem because the whole script block needs to be parsed before the first instruction is executed. With any bogus content following an exit instruction, the script would fail to parse at all, even though that code would never be reached.
If the free text was a single line, you could get away with a trailing //. Doesn't work for multi-line comments though, as you would need a closing */. Same for conditional-comments requiring /*#end #*/.
Related
I'm not the best at explaining this stuff but here I go.
I have a program that uses "tesseract.js" to read an image every second or so.
10% of images have an "Empty page!!" error message, but I don't need or want this error message flooding my otherwise useful error log. I want to remove it from the source code, however, it isn't fired from the easily readable js code...
I assume it is fired from the wasmBinaryFile section, which (if I understand correctly) is a wasm binary compiled version of the original C++ (Tesseract 4.1.1)
In C++ Tesseract, the error message is fired from \src\textord\colfind.cpp line 366. If I knew where the equivalent section of the binary code was, I assume that I could remove it.
I know that decompiling wasm to C++ won't necessarily be understandable, but if I did it, would I be able to compare it to the source code for Tesseract and either find the section I need to remove or be able to recompile it for use again?
If so, would someone be able to point me towards a good software to do this?
You don't need to revers engineer that code, tesseract is open source, has a github page and you can look at the source code here :
https://github.com/tesseract-ocr/tesseract/blob/main/src/textord/colfind.cpp.
It also means you can use git to get a local copy, modify and compile it. Probably you can even find a way to change tprintf
Is there a way to run a program (for example: tcpdump) and every time it shows something through the console, from nodejs capture it and return the result to print in an html? no need to save it, keep it in real time.
My idea is that a program can be executed and while it is running and showing things in the console, they can be sent to the html where you can progressively see all the results of the program's execution.
Thanks for help.
I think using socket io is a good solution,
check there get started tutorial
No need to do anything like "capturing output" in Node.js. You can use the heredoc available in almost every shell. The heredoc, in the most basic sense, redirects the output of a command to a file. In your example, if you use tcpdump, here's what you'd do:
$ tcpdump [options] >> file.html
The >> heredoc operator appends to a file(create if doesn't exist). This means if you already have some content in file.html, the content will still be there, and the output will be appended to the end of the file.
The > heredoc writes to a file(also, create if doesn't exist). So, if you have some content in file.html, that will be overwritten with the new content.
I came across some interesting behaviour of the javascript code on my XPages
//'rdoGeschlecht1' is present on page Basis (no problems there),
//but not on page 'Stufe1'.
var level = "Stufe1";
if(level == "Basis")
{
alert("1");
// var rdoGeschlecht1 = '#{javascript:getClientId("rdoGeschlecht1")}';
}
else if(level == "Stufe1")
{
alert("2");
}
The code above always ends in an error when executed on a page where the element is not present - "Ungültiger Komponentenname rdoGeschlecht1 kann in getClientId nicht aufgelöst werden." - it seems to me that Notes tries to resolve the object ID even if the line is not used in the actual execution and even when uncommented.
I have found a quick&dirty workaround of course, but I am surely not the first one to stumble upon this behaviour and I would really be interested in how experienced XPages programmers would be going about this?
The problem is you're commenting out the client-side JavaScript which is going to be run on the browser. But the server-side JavaScript code within #{javascript: (which needs to run on the server) is not commented out.
Perhaps it will help to explain what happens you put SSJS or EL in a string property or, in this case, a script block. Because the key is that the CSJS is not parsed on the server, it's just passed as a string to the browser.
The parser reads the string and looks for #{javascript: which tells it that the following code up to the closing } needs to be passed to the SSJS parser and the result added to the string that gets written to the browser. Any lines within that SSJS block that begin "//" will get omitted. But the parser will not take into account anything outside the #{javascript: because that is just text being passed to the browser. It is the browser that interprets the whole thing as client-side JavaScript.
Hopefully that clarified why it's working the way it is.
If you want to comment out a line in a script block that includes SSJS and you want to prevent the SSJS from running, you'll need to comment out the CSJS (so the browser doesn't run it) and the SSJS (so the server doesn't run it).
I stumbled upon a bit of code that creates a popup, and you can edit the text from it, add multiple lines...
mshta javascript:alert("Line 1\n Line 2");close();
Go ahead and fire up command prompt and enter in that line. I guess that the \n means next line, as you can add/delete those all you want.
My question is, is there a way to use that same popup method, but rather than have a single button that says "OK", use two buttons, that when you click one, you "goto a", and when click the other, you "goto b".
I also can't figure out how to modify that other popup that I posted above, to say change it from "HTML APPLICATION" to some other title, and rename the "OK" button to something else. Either way, that is beside the point, and just curiosity kicking in.
EDIT: In my last comment, about closing the script, I figured out that I can just throw
;close();
at the end of the parentheses. But how can I set the true/false as a variable in the batch script?
EDIT: I have decided that autoit is a much better language for this kinda thing. Voting to have closed.
Ok, first let me explain what is going on in your example. When you type in:
mshta javascript:alert("Line 1\n Line 2");close();
what you're actually doing is telling your computer:
Run the program called mshta.exe, and pass the following javascript to it as an argument
You can do this with any program, for example, try opening notepad with a new file called "banana.txt" by typing:
notepad banana
Note that both cases have virtually nothing to do with batch. In your example, mshta.exe just runs some javascript to open an alert window, just as in my example notepad.exe deals with the creation of the .txt file.
Ok, so now that we've got that out of the way, onto your actual question: Is there a way to write a script in batch that will open a popup confirmation window?
The simple answer to your question is no. Batch is very good[citation needed] at moving around directories, opening files/programs, and...that's about it. If you need to do anything that isn't in that list, you should really be using a different scripting language.
However, while I cannot emphasize enough how much that is the correct answer to your question, I recognize that it's not a very satisfying one, so I will say that if you absolutely have to have a solution in batch, I would do something like the following:
#echo off
echo code=Msgbox("I'm A Message Box!", vbYesNo, "I'm The Title!") > "%temp%\popupBox.vbs"
echo WScript.Quit code >> "%temp%\popupBox.vbs"
cscript /nologo "%temp%\popupBox.vbs"
if %errorlevel%==6 call :ok_tag
if %errorlevel%==7 call :cancel_tag
echo Done!
exit /b 1
:ok_tag
echo You pressed Yes!
exit /b
:cancel_tag
echo You pressed No!
exit /b
This code essentially circumvents your problem by creating and running a temporary vbscript file (another scripting language) whose job is to display a confirmation window for you, and then using the exit code from that script to determine which button was clicked.
Notice again how much longer and more complicated this is than simply writing the program in pure vbscript to begin with, but if you must have a .bat file, then a .bat file you shall have.
#echo off
for /f "usebackq" %%f in (
`mshta "javascript:new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(new ActiveXObject('WScript.Shell').PopUp('Select one',0,'Title',36));close();"`
) do (
if "%%f"=="6" (
echo YES
) else if "%%f"=="7" (
echo NO
) else (
echo ????
)
)
I am working on calling a .exe file with a WScript.shell activeX. The file is wkhtmltopdf.exe and it is used to convert a HTML page to a .pdf. Everything is working well when I am just calling C:\wkhtmltopdf.exe in the code. It runs and then closes correctly. But my issue is you need to run it from cmd with the program name then the HTML file name you are reading followed by the .pdf name you want it to be created as.
For example:
c:\wkhtmltopdf.exe c:\PDFTestPage.html c:\TEST.pdf
This will call wkhtmltopdf.exe, read c:\PDFTestPage.html, then create c:\TEST.pdf. Works fine when I type it into cmd.
Does anyone know an activeX that will not just run and .exe but actually execute a command line?
Here is my code that I am currently using.
function callShellApplication(){
var objShell = new ActiveXObject("WScript.shell");
objShell.run('"c:\wkhtmltopdf.exe"');
}
Would really like it to be the following.
function callShellApplication(){
var objShell = new ActiveXObject("WScript.shell");
objShell.run('"c:\wkhtmltopdf.exe c:\PDFTestPage.html c:\TEST.pdf"');
}
Also side note. For some reason I cant launch the .exe from an absolute path. I have to move to the directory and then just type in wkhtmltopdf.exe. The fill path is:
C:\Program Files (x86)\wkhtmltopdf\wkhtmltopdf.exe
I really only work with UNIX so I'm not sure about spaces in the path. I can do a chdir with the spaces but I cant use the fill path when executing it. Any information would be helpful. Thank you in advance.
According to the following:
http://msdn.microsoft.com/en-us/library/d5fk67ky%28v=vs.84%29.aspx
You should be able to pass the commands directly as part of the strCommand param, you'd probably be better off getting rid of the extra quotes wrapping the entire command and arguments:
function callShellApplication(){
var objShell = new ActiveXObject("WScript.shell");
objShell.run('c:\wkhtmltopdf.exe c:\PDFTestPage.html c:\TEST.pdf');
}
Also you should be able to handle spaces in paths by wrapping each item in quotes, like so:
function callShellApplication(){
var objShell = new ActiveXObject("WScript.shell");
objShell.run('"C:\Program Files (x86)\wkhtmltopdf\wkhtmltopdf.exe" "c:\PDFTestPage.html" "c:\TEST.pdf"');
}
You should also keep in mind whether you want to bWaitOnReturn or not, and which intWindowStyle you need (some executables may benefit from a particular style).
Also just as a cautionary note — it's been a while since I've used WScript.shell — but you may need to escape your backslashes in your paths. So a path may need to look like the following:
objShell.run('"C:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe"');
For anyone else that comes across this issue, I had a similar (but slightly different) problem that I thought I'd share.
I too wanted to run a command using the ActiveXObject("WScript.shell. I needed to run a .bat script that would launch Google Chrome to a specific URL.
The JS I had was as follows:
var objShell = new ActiveXObject("WScript.shell");
objShell.run('"C:\\Scripts\\MyChromeBat.bat" MY_URL');
This would properly launch my .bat script which was very simple:
start "" chrome.exe %1
The issue I came across was that MY_URL contained some query parameters and when I used the above JS, the query params would be stripped to an extent. So when I was trying to open
http://localhost:8080/webapp/mypage.html?param1=test¶m2=test2
it would actually open
http://localhost:8080/webapp/mypage.html?param1
The fix turned out to be simple - I had to surround MY_URL in quotes. So I modified the line
objShell.run('"C:\\Scripts\\MyChromeBat.bat" MY_URL');
to be
objShell.run('"C:\\Scripts\\MyChromeBat.bat" "MY_URL"');