ProcessStartInfo with powershell - processstartinfo

Hello i have problem i want to open a powershell sciprt, while i use Process.Start everything work, but windows popup for a second, and thats why i want to use ProcessStartInfo, but i make something wrong.
ProcessStartInfo startInfo = new ProcessStartInfo("powershell.exe")
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
//Arguments = "nologo -WindowStyle Hidden -ExecutionPolicy UnRestricted",
FileName = #"C:\\Users\\Kirlen\\Documents\\temp_skrypt_run.ps1",
};
Process.Start(startInfo);
im getting System.ComponentModel.Win32Exception: while try to run it
i would like to ask for help to fix that code

Related

After updating nativescript folder and files are not creating in my android phone

I'm able to create a folder if it not exists and save a newly written file in that folder previously. but after updating to latest nativescript the same code was not working and not give error properly.
and also I'm getting an error
Error: android.util.AndroidRuntimeException: Calling startActivity() from >outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. >Is this really what you want?
const fileSystemModule = require("tns-core-modules/file-system");
const documents = fileSystemModule.knownFolders.documents();
documents._path = "/storage/emulated/0/";
const folder = documents.getFolder('Reports/sample/');
const file = folder.getFile('fileName.xlsx');
file.writeText(viewModel.get("fileTextContent") || html_content)
.then((result) => {
return file.readText()
.then((res) => {
var toast = Toast.makeText("Exported to Excel Succesfully");
toast.show();
return res;
});
}).then((result) => {
console.log("---result---");
console.log(result); // im getting result, a html string
var intent = new android.content.Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(android.net.Uri.fromFile(new java.io.File(file._path)), "application/vnd.ms-excel");
application.android.context.startActivity(android.content.Intent.createChooser(intent, "Open Excel..."));
}).catch((err) => {
console.log(err);
});
before updating it was working fine. but now I don't know what happened to this.
It's a new requirement from Android itself. You must add FLAG_ACTIVITY_NEW_TASK flag to your intent.
With Android 9, you cannot start an activity from a non-activity context unless you pass the intent flag FLAG_ACTIVITY_NEW_TASK. If you attempt to start an activity without passing this flag, the activity does not start, and the system prints a message to the log.
intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

How casperjs passing arguments with space?

casperjs script.js "myurl" "myemail" "my name"
Here is the script:
url = (casper.cli.get(0));
email = (casper.cli.get(1));
name = (casper.cli.get(2));
this.echo(name);
console.log(name);
The result is: my (and not my name).
I also tried with single quotes.
You can just escape the spaces with a backslash and DON'T use quotes, for example:
casperjs test.js myurl myemail my\ name
I don't know for sure if it is dependend to the console you are using, under ubuntu (docker) that worked for me:
var casper = require('casper').create();
var targetUrl = 'http://www.test.com/';
casper.start(targetUrl, function() {
url = (casper.cli.get(0));
email = (casper.cli.get(1));
name = (casper.cli.get(2));
this.echo(url);
this.echo(email);
this.echo(name);
console.log(name);
});
casper.run();
Result was:
myurl
myemail
my name
my name
For a windows command line that worked:
casperjs test.js myurl myemail \"my name\"

Are there any progressing development to solve debug/release differentiation within Task Runner Explorer?

The last post I've found about this topic is from autumn 2015. I think this is one of those basic things every developer will need sooner or later.
I would like to differentiate my gulp tasks based on actual build configuration (debug/staging/release) etc. I don't actually need to connect it with Visual Studio's solution configuration.
Here is a proposed solution: we would have this as an option inside Task Runner Explorer, and then at task binding I could tick in in which configurations I would like to run the task.
Is it only me who would need this?
I don't use TRX but you can bind any of these tasks to an event like "Project Open" or "Before Build." I use gulp-if and set variables in my parent task, then call all child tasks with run-sequence. (untested code)
gulpfile.js
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
requireDir = require('require-dir')('./js/gulp/tasks'),
runSequence = require('run-sequence'),
vars = require('./variables');
gulp.task('dev', function(){
vars.isProduction = false;
runSequence('clean', ['css', 'scripts']);
});
gulp.task('prod', function(){
vars.isProduction = true;
runSequence('clean', ['css', 'scripts']);
});
/js/gulp/tasks/scripts.js
gulp.task('scripts', function () {
return gulp.src('scripts/**/*.js')
.pipe($.concat('app.min.js'))
.pipe($.if(vars.isProduction, $.uglify()))
.pipe(gulp.dest('/js'))
.pipe($.plumber({
errorHandler: vars.onError
}))
.pipe($.if(!vars.isProduction, $.livereload()));
variables.js
module.exports = {
isProduction: false,
onError: function (err) {
log(err);
}
};

How to ensure node.js child_process.spawn will write error messages to the console

I'm having a lot of trouble running child processes and getting their output written to the console. In this episode, I'm trying to use spawn to run a windows mklink command. The error is the that I don't have permission to write the file.
My problem, though, is that the error isn't told to me in any way.
The following prints You do not have sufficient privilege to perform this operation. to the console:
mklink /D C:\some\path\to\my\intended\link C:\path\to\my\folder
But running this in node.js only gives me Error: spawn ENOENT - which is a highly useless error message:
require('child_process').spawn('mklink',
['/D', 'C:\\some\\path\\to\\my\\intended\\link',
'C:\\path\\to\\my\\folder'],
{stdio:'inherit'})
I get nothing on the console, despite the stdio:'inherit'. I've also tried the following:
var x = require('child_process').spawn('mklink',
['/D', 'C:\\some\\path\\to\\my\\intended\\link',
'C:\\path\\to\\my\\folder'])
x.stdout.pipe(process.stdout)
x.stderr.pipe(process.stderr)
But no dice. No console output at all. Note that I do get console output with exec:
var x = require('child_process')
.exec('mklink /D C:\\some\\path\\to\\my\\intended\\link C:\\path\\to\\my\\folder')
x.stdout.pipe(process.stdout)
x.stderr.pipe(process.stderr)
This shouldn't need any special knowledge of how windows mklink works - my problem is simply with error reporting with node.js spawn.
What am I doing wrong here? Is this a bug in node.js?
Update: It seems this bug has been fixed by node v0.10.29
For me stdio wasn't working.
Try this:
// Helper function to execute and log out child process
// TODO: implement a better success/error callback
var spawnProcess = function(command, args, options, callback) {
var spawn = require('child_process').spawn;
var process = spawn(command, args, options),
err = false;
process.stdout.on('data', function(data) {
grunt.log.write(data);
});
process.stderr.on('data', function(data) {
err = true;
grunt.log.errorlns(data);
});
if (typeof callback === 'function') {
process.on('exit', function() {
if (!err) {
return callback();
}
});
}
};
spawnProcess('mklink', ['/D', 'C:\\some\\path\\to\\my\\intended\\link', 'C:\\path\\to\\my\\folder'], {}, done);
As a workaround, try the following:
require('child_process').spawn('cmd',
['/C', 'mklink', '/D', 'C:\\some\\path\\to\\my\\intended\\link',
'C:\\path\\to\\my\\folder'],
{stdio:'inherit'})

How to get Casper JS to return an exit code that indicates test success status?

I want to be able to have a set of Casper JS tests and get an exit code back of 0 on success and non-zero on error or test failure (I want to run the casper command from java and determine if a test passed).
The problem I am having is that an exit code of 0 is always returned. Here is an example test where this happens:
var casper = require('casper').create();
casper.start('http://www.google.com', function() {
this.test.assertEquals(true, casper.cli.options['value']);
});
casper.run(function() {
casper.test.done(1);
});
All of the following commands result in an exit code of 0:
C:/casperjs/bin/casperjs test --value=true C:/Temp/simpletest.js
C:/casperjs/bin/casperjs test --value=false C:/Temp/simpletest.js
C:/casperjs/bin/casperjs --value=true C:/Temp/simpletest.js
C:/casperjs/bin/casperjs --value=false C:/Temp/simpletest.js
How can I invoke Casper and determine whether the tests succeeded or failed/errored from Java?
First, you cannot overwrite the casper instance in test mode, see http://docs.casperjs.org/en/latest/testing.html#test-command-args-and-options
Remove
var casper = require('casper').create();
from your code.
Then try
casper.start('http://www.google.com', function(test) {
test.assertEquals(true, casper.cli.options['value']);
});
Start casperjs with
--fail-fast
so that each test will exit with code 1.
Then in Java
String[] args = {"/bin/sh", "-c", "casperjs test --fail-fast simpletest.js"};
Process proc = Runtime.getRuntime().exec(args);
logger.log(Level.INFO, IOUtils.toString(proc.getInputStream()));
String warnings = IOUtils.toString(proc.getErrorStream());
if (StringUtils.isNotBlank(warnings)) {
logger.log(Level.WARNING, warnings);
}
int exitValue = proc.exitValue();
assertEquals(0, exitValue);
Of course you need to change the paths to suit your environment.
Hope that helps!
The problem I am having is that an exit code of 0 is always returned.
Your casper test should be like that:
var casper = require('casper').create();
var system = require('system');
var param;
casper.start('http://www.google.com', function() {
//get parameter from command line
system.args.forEach(function (arg, i) {
if(arg.search(/--value=/i) != -1){
param = arg.replace(/--value=/g, "");
}
});
this.test.assertEquals(true, Boolean(param));
});
casper.run(function() {
this.test.done(1);
this.test.renderResults(true);
});
To run:
casperjs simpletest.js --value=true
How can I invoke Casper and determine whether the tests succeeded or failed/errored from Java?
You should look this answer:
CasperJS passing data back to PHP
Return the Predefined code for failure (for eg for us we gave 99 (random))
//Capture all fails
casper.test.on("fail", function () {
casper.exit(99);
});
Similarly you can define different code for other issues at high level
eg: to get the retry logic in place we can use onWaitTimeout codes
casper.options.onWaitTimeout = function () {
casper.screenCapture('POETerror', true);
this.exit(98);
};

Resources