"No Matching Files Found" Running Sigcheck (Node.js) with execSync - javascript

I am writing a program in Javascript (Node). In this program I want to get an executable's version number with the Windows Sigcheck tool, but it is giving me "No matching files found."
I can run Sigcheck from the command prompt and it works fine:
Sigcheck finds the executable, and the output is the executable's version number.
But when I run the same command through Node's child_process execSync(), Sigcheck cannot find the file. I run this code:
let appVersionNumber = execSync('\\path\\to\\sigcheck.exe -n "C:\Program Files\Autodesk\Maya2017\bin\maya.exe"');
And I get this output instead:
"No matching files found"
How can I run Sigcheck in Node to get the executable's version number? It is definitely running Sigcheck because it is displaying the banner, but I do not understand why it can't find the executable. Any help would be appreciated- thanks!

You need to escape backslashes in the param string too:
let appVersionNumber = execSync('\\path\\to\\sigcheck.exe -n "C:\\Program Files\\Autodesk\\Maya2017\\bin\\maya.exe"');
Otherwise they'll just be skipped (it's how slashes are treated in string literal in JavaScript), and you'll get the wrong path with no files for sigcheck to, well, check.
BTW, if I were you, I'd probably have put those pathes into separate variables:
const sigcheckPath = '\\path\\to\\sigcheck.exe';
const appPath = 'C:\\Program Files\\Autodesk\\Maya2017\\bin\\maya.exe';
let appVersionNumber = execSync(`${sigcheckPath} "${appPath}"`);

Related

webpack require with dynamic path

My colleague put something like this in our code:
const information = require('../relative/path/' + tag + '.json');
The funny thing is that it works, and I don't really see how.
I have created this minimal project:
$ head *.json main.js
==> 1.json <==
["message #1"]
==> 2.json <==
["message two"]
==> 3.json <==
["message III"]
==> package.json <==
{
"dependencies": {
"webpack": "^5.38.1"
"webpack-cli": "^4.7.2"
}
}
==> package-lock.json <==
...
==> main.js <==
const arg = process.argv[2] ? process.argv[2] : 1;
console.log(require(`./${arg}.json`)[0]);
when I run the original program, I get this:
$ node main.js 1
message #1
$ node main.js 2
message two
$ node main.js 3
message III
so now I compile with webpack
$ node_modules/.bin/webpack ./main.js
and it creates a dist directory with a single file it in, and that new bundled program works too:
$ node dist/main.js 1
message #1
$ node dist/main.js 2
message two
$ node dist/main.js 3
message III
and when I look inside the bundle, all the info is bundled:
When I remove the require from the program, and just print the arg, the bundled program is a single line.
So how does it do it?
somehow calculate every possible file?
just include everything from the current directory down?
Funny thing is in my simple example, package.json ended up in there too, but in the real one that gave me the idea, it didn't.
Does anybody know how this works?
I mean the simple practical answer for me is, never put variables in require... but I am still curious.
PS the real one is a web project. just used node and args for the example
Webpack always bundles all require'd files into the final output file (by default called bundle.js). You cannot require anything that was not bundled.
If you require something that is not a constant, as you pointed out, it might lead to some trouble. That is why eslint has a no-dynamic-require rule for that. But if you know what you are doing, everything is just fine.
Webpack uses some heuristics to support non-build-time-constant values (i.e. expressions) for require. The exact behavior is documented in webpack's documentation on dependency management.
As explained in that link, your require('../relative/path/' + tag + '.json') will lead webpack to determine:
Directory: ../relative/path
Regular expression: /^.*\.json$/
And will bundle all files matching that criterion.
When your require call is executed, it will provide that file that matches it exactly, or throw an error if that file was not bundled.
Important: This means, of course, that you cannot add files after bundling. You must have files in the right place, before bundling, so they can be found, added and ultimately resolved by webpack.
Also note that often times, you don't need to write your own webpack experiments. Webpack has plenty of official samples. E.g. your case is illustrated exactly by this official webpack sample.

/bin/sh: node: command not found - in VScode, running Javascript

Im trying to run this simple code in VSCode for learning Javascript but I keep getting this error:
[Running] node "/var/folders/xr/30nkhmxs7159fblbjtfj2jhw0000gn/T/tempCodeRunnerFile.javascript"
/bin/sh: node: command not found
[Done] exited with code=127 in 0.014 seconds
I've looked online and have tried changing the CodeRunner Executable Map as I saw in another post but it doesn't seem to be helping.
Thanks!
let admin, name; // can declare two variables at once
name = "John";
admin = name;
alert( admin ); // "John"
First of all, check the output of which node in the default terminal application. If the output is empty, this means that the path where the node binary resides is not in your $PATH.
Try to find the location of the node executable. After this, check what's the shell you're using by running echo $SHELL. If it returns something like /bin/bash, create a file(may already exist) named ".bash_profile" or ".bashrc" and there, add the following: export PATH=$PATH:<location of node>, replacing <location of node> with the actual location of the node binary.
in this page: How to run javascript code in Visual studio code? /bin/sh: 1: node: not found
dmcquiggin had resolve this problem:
Locate the path to your Node executable, by typing the following command in a terminal:
which node
The result will be similar to the following (I use nvm to manage my Node versions, yours might look a little different)
/home/my_username/.nvm/versions/node/v10.15.1/bin/node
Make a note of / copy this path.
Open VS Code. Either press Ctrl+, (on Linux), or from the File menu, select Preferences > Settings.
In the search box at the top of this window, type:
Executor Map
Click the 'Edit in settings.json' link displayed under the first result.
Add the following to the end of the settings file, replacing the path with the one from step 1.
"code-runner.executorMap": {
"javascript": "/home/my_username/.nvm/versions/node/v10.15.1/bin/node"
}
this also works on my mac, cheers

Convert the ssd_mobilenet_v1_coco model with tensorflow_js

I want to build an app with javascript which integrates object-detection. For this, I wanna use the ssd_mobilenet_v1_coco model and use it in tensorflow.
However this line of code:
C:\Users\Jonas\AppData\Roaming\Python\Python36\Scripts\tensorflowjs_converter --input_format=tf_saved_model --output_node_names='image_tensor, detection_boxes, detection_scores, detection_classes, num_detections' \saved_model\saved_model \saved_model\web_model
does not work. It gives me file not found error, but the file is actually there unless I'm very dump and turned back into computer beginner.
OSError: SavedModel file does not exist at: \saved_model\saved_model
Also, I'm not quite sure about the output node names but this is secondary.
Thanks for support, hopefully I'm not totally dump :)
This might be because you are using an absolute path instead of a relative path.
On mac or linux, if you are in the directory that contains the downloaded unzipped model, you would run a command of that type :
tensorflowjs_converter --input_format=tf_saved_model --output_node_names='detection_boxes,detection_classes,detection_scores,num_detections' --saved_model_tags=serve ./ssd_mobilenet_v1_coco/saved_model ./ssd_mobilenet_v1_coco/web_model
From what i can see you are on Windows.
If you are running your command from the directory that contains the saved_model folder, you should run the following command :
C:\Users\Jonas\AppData\Roaming\Python\Python36\Scripts\tensorflowjs_converter --input_format=tf_saved_model --output_node_names='image_tensor, detection_boxes, detection_scores, detection_classes, num_detections' .\saved_model\saved_model .\saved_model\web_model

Textmate Javascript Validate Syntax Command

I spend a lot of time in TextMate 2 writing PHP and a lesser amount writing Javascript.
I've always found the Validate Syntax command in Textmate very useful as a final quick sanity check before saving. I was wondering today if there were a way to do something similar for Javascript and I think I've found a solution in acorn:
https://github.com/ternjs/acorn
Running something along these lines:
acorn --silent <file-here>; echo $?
Returns either a 0 if it's valid or a 1 if it's not. If not it also returns an error with the line where the syntax error occurs:
Unexpected token (50:1)
1
Seems like it's almost perfect for use in a simple Validate Syntax command.
But that's where I ran into a brick wall of ignorance. I'm not sure how to get from there to an actual command in TextMate and looking at the PHP example and a few others left me no further along partly because I've got almost no Ruby experience and it appears to that's how commands are usually written in TextMate.
Anyone with more experience writing TextMate commands care to take a pass at it?
Based on Graham's suggestion and additional help here's a working command:
#!/usr/bin/env bash
#Write scope of JS to a temp file
echo "$(</dev/stdin)" > ${TMPDIR}acorn-validation.js;
#Capture output of acorn syntax check (Note that acorn sends the output to STDERR thus the 2>&1)
ACORN_OUTPUT=$( (acorn --silent ${TMPDIR}acorn-validation.js) 2>&1 );
echo 'Running syntax check with acorn...';
if [[ "" == $ACORN_OUTPUT ]]; then
echo 'No syntax errors detected';
fi
if [[ "" != $ACORN_OUTPUT ]]; then
#Find the line/column value
LINE=$(echo $ACORN_OUTPUT | grep -oE '([0-9]+:[0-9]+)';);
echo '';
echo 'Syntax error on '${LINE};
echo ${ACORN_OUTPUT/($LINE)/};
#Send cursor to the place where the error occured
LINE=(${LINE//:/ });
open "txmt://open/?url=file://${TM_FILEPATH}&line=${LINE[0]}&column=${LINE[1]}";
fi
Make sure Input is set to Scope and Output is set to Show in Tool Tip.
Install Acorn globally:
npm install -g acorn
Find out where acorn been installed:
which acorn
Mine said (because I use nvm):
~/.nvm/versions/node/v6.2.2/bin/acorn
Add that bin folder to your TextMate Path, use a colon to delineate:
So my PATH is:
$PATH:/opt/local/bin:/usr/local/bin:/usr/texbin:/usr/local/bin:$HOME/.nvm/versions/node/v6.2.2/bin:$HOME/.rvm/rubies/ruby-2.3.3/bin
Now open the bundle editor:
Create a bundle, or open an existing, and press cmd+n to create a new file, select "command" from the dropdown.
Paste this into the command, cmd+s to save.
Update: This command has been brought from proof of concept to functional by (OP) Jamie Poitra, so check the question for his script.
#!/usr/bin/env bash
acorn ${TM_FILE}
All set.

Using shell.js with cat command in node.js

I need to use shelljs in Node.js. I write this two lines for getting standart output and writing it into something.xml file by using cat command. But with this style, the stdout will shown in the terminal. I don't want to it. How can I fix it ? Do I need to use something different ? I don't want to anything in the terminal about stdout, I need "stdout" only in a file.
var sh = require('shelljs');
var xyz = sh.cat('./something.xml').stdout;

Categories

Resources