I have a file stored in local computer and a printer connected too. So generally if I want to give a print of the file to the connected printer, I would run following command in command prompt:
cd <path where the file is locally stored>
copy <filename.ext> <portname in which the printer is connected>
So for example, if I have a file at path /Users/chandrani.chatterjee/Desktop/TestFolder
and a printer connected at port lpt1
I would write following commands in command prompt
cd /Users/chandrani.chatterjee/Desktop/TestFolder
copy testfilename.txt lpt1
So this would print my testfilename.txt
No I want to achieve this on a button click in ReactJs.
I searched the web and found out about shellJs
but I am not sure on how to fire the commands using it.
I tried
var sh = require('shelljs');
const { stdout, stderr, code } = sh.exec('cd /Users/chandrani.chatterjee/Desktop/TestFolder', { silent: true });
I also tried
var sh = require('shelljs');
var output = sh.exec('java -version', {silent:true}).stdout;
but getting error in both the scenarios
Cannot read property 'stdout' of null
How to do this correctly?
EDIT:
For example in .Net the same can be achieved with below code:
function create_send_file() {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("c:\\FilePrn\\label.prn", true);
s.WriteLine("some string");
s.Close();
var newpath = fso.CopyFile("c:\\FilePrn\\label.prn", "lpt1");
}