jharding / grunt-exec Goto Github PK
View Code? Open in Web Editor NEWGrunt plugin for executing shell commands.
Home Page: https://npmjs.org/package/grunt-exec
License: Other
Grunt plugin for executing shell commands.
Home Page: https://npmjs.org/package/grunt-exec
License: Other
Hi,
I get this warning on all commands:
Cannot read property 'orig' of undefined Use --force to continue.
I use the basic setting for list_files in your README
I don't know what the problem is?
sometime when we exec a shell, and want to catch the output, filter some keyword then output.
I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.
If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.
If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8"
as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0"
to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.
Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.
Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!
If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.
Thanks, we really appreciate your work!
I'm running a task as follows:
try {
grunt.task.run("exec:run_nw");
} catch(e) {
grunt.log.writeln("node-webkit not found. Downloading required binaries. Run 'grunt run' once files are downloaded.");
grunt.task.run("nodewebkit");
}
If exec:run_nw fails, I'd like to try and handle the error. In this case, exec:run_nw is trying to run files that don't exist, so instead, I want to retrieve them. However, grunt just fails without utilizing the catch block.
Is there something I'm missing in order to catch errors from the exec module so I can correct them at runtime?
Thank you,
Hi,
This is my code:
exec: {
wp_download: {
cmd: 'wp core download --locale=<%= wp.download.locale %> --version=<%= wp.download.version %>'
}
},
But when I try to run my task, it says Warning: Task "exec:wp_download" not found.
Hope you can help :)
exec: {
echo_something: 'echo "This is something"',
cmd: 'lessc --source-map=main.map less/main.less css/main.css',
cmd: 'lessc --source-map=file2.map less/file2.less css/file2.css'
},
which execute last cmd only
How should this work? Should they execute sequentially or be appended together with &&?
Issue #66 shows an example of syntax near the bottom
Is there any way to use sudo
with this task? I have a command that I want to run, but it requires admin permissions.
Successful run
Config:
dist_dev_ks: {
command: [
[
'ps -ef',
'grep python',
'grep runserver',
'grep 9474',
"awk '{print $2}'",
].join(' | '),
].join(' && '),
},
Execution:
$ grunt exec:dist_dev_ks
Running "exec:dist_dev_ks" (exec) task
94833
94836
94897
Done, without errors.
Failed run after adding the piping to xargs kill
Config:
dist_dev_ks: {
command: [
[
'ps -ef',
'grep python',
'grep runserver',
'grep 9474',
"awk '{print $2}'",
'xargs kill',
].join(' | '),
].join(' && '),
},
Execution:
$ grunt exec:dist_dev_ks
Running "exec:dist_dev_ks" (exec) task
>> Exited with code: 0.
Warning: Task "exec:dist_dev_ks" failed. Use --force to continue.
Aborted due to warnings.
If I use --verbose:
Expecting exit code 0
>> Exited with code: 0.
Warning: Task "exec:dist_dev_ks" failed. Use --force to continue.
On W7, version "grunt-exec": "~0.4.5"
I'll try the most basic cmd: echo
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
exec: {
update_po: {
cmd: 'echo "hello"'
}
},
});
// Default task(s).
grunt.registerTask( 'default', 'exec' );
};
Result:
What did I missed, something to add somewhere
Grunt and grunt-cli work without any issue ;)
Thanks
Hello!
I am running a compile command that generates a lot of output. As maxBuffer limit is reached, grunt outputs "Done, without errors", and proceeds with the next task, while the compile task continues in the background.
This behaviour is really confusing, there should be a clear error statement.
(running grunt-exec 1.0.0)
Hi, I'm trying to use this to automate the running of a bash script that sets environment variables in my project. If I just personally run the command 'source ./my_script.sh' then it works just fine. But if I put that same command into grunt-exec, it says that it runs without errors, but the vars aren't actually set.
Any thoughts on what the issue is?
Thanks! - Blake
absolute (like here) or relative:
symlink:
bower_components:
target: 'bower_components'
link: '/Users/atrapp/development/sentialfive/public/bower_components'
creates only bower_components -> bower_components link which is pretty useless ;)
The cwd is sometimes not known until execution time. It would be nice to be able to set it from a function. Something like:
grunt.initConfig({
exec: {
sample: {
command: {...},
cwd: function() {
return "/my/dynamicpath";
}
}
}
});
Would a pull request for something like that be merged into grunt-exec?
i just try below, but it doesn't work.
childProcess.on('error', function(error){
log.error(error);
})
i test in callback just like below, it works:
childProcess = cp.exec(command, execOptions, function(error, stdout, stderr){
if(error !== null){
log.error(error);
}
callback(error, stdout, stderr);
});
someone has any good idea? and know why?
Hello,
I'm using your grunt task and want to work with the stout/sterr of the command. Is there some API, which allows me to get the return value of a command?
Example:
grunt exec:ret_command:whoami
ret_command: {
cmd: function(command) {
var who =
return command;
}
}
Or if I use
grunt exec:who
who:{
command: 'whoami',
stdout: true,
stderr: true
},
to redirect the stdout or/and sterr to a function, where I can deal with the result of 'whoami'?
BR & THX,
mybecks
Hi,
I would like to foreach through an array and then fire a command on each iteration:
wp_plugins: {
cmd: function() {
var plugins = this.config('wp.plugins');
plugins.forEach(function(plugin){
return 'php wp-cli.phar plugin install ' + plugin + ' --activate --force';
});
}
}
With the code above I get this error:
Running "exec:wp_plugins" (exec) task
Command property must be a string.
Can you help me? Thanks!
Gijs
Hey, I wrote a grunt plugin that checks the current node version against engines.node
in the project's packages.json
and extends grunt-exec
tasks by prepending the commands with an nvm use
command if necessary. I thought you might want to link to it in your README.
Currently on ~0.4
, should be fixed since this will prevent projects from upgrading to the latest version of Grunt.
bower register grunt-exec git://github.com/jharding/grunt-exec.git
might have to duplicate the package.json
to bower.json
and change peerDependencies
to dependencies
or some such small tweaks, but that's it I guess. Up to you guys though :) just noticed it wasn't in there when I ran bower search grunt
.
Peace, Tom
I have a task that runs a grunt watch, and I would like to execute a command after that watch task has been exited. Is this possible with grunt-exec?
I want grunt-exec to start my MAMP server when my development task is run and then stop it after the watch is exited with Ctrl-C.
I use this plugin with watch plugin for autostart tests.
How can I see colroful output from my script under exec:test
task ?
When I execute a command, in my case cordova build android --release
, that prompts me to enter the password to unlock my signing key, I can enter text but when I hit return I just get a new line and the input doesn't propagate the command in progress, halting the script execution. I've checked the readme and closed issues but can't find anything related to a solution to this?
Thanks
I've setup exec to run rpmbuild and it did for a while until we changed something in the packaged files then it started failing.
Grungfile.js :
build_rpm:{
cmd: 'rpmbuild -ba <%= rpm_dir %>/SPECS/cdr.spec'
}
Output:
....
....
Exited with code: 0.
Warning: Task "exec:build_rpm" failed. Use --force to continue.
Aborted due to warnings.
I am trying to create mysql database using grunt task and following command.
mysql -u "${DB_USER}" -p"${DB_PASSWORD}" -e "CREATE DATABASE IF NOT EXISTS ${DATABASE}
;"
The database name have dash(-) in it so i have to put "`" before name, escaped with "" which cannot be seen here. This works when I run it on shell directly.
But when running with grunt, i am getting following error:
/bin/sh: 1:
test-db: not found
ERROR
1064 (42000)
at line 1
: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Exited with code: 1.
Warning: Task "exec:create_database" failed. Use --force to continue.
In an effort to cut down repetition in gruntfiles, I was thinking about modifying this plugin to allow simple commands to be even more simple:
exec: {
echo: {
cmd: 'echo whatwhat'
}
}
Could become:
exec: {
echo: 'echo whatwhat'
}
But before I added it, I figured I'd ask here first. I have quite a few grunt files that end up having the same few commands, and the extra lines just add a lot of noise.
Hi,
I'm using grunt-contrib-watch task to monitor a folder in which some sh scripts are placed (and removed) on the fly. In those scripts, there's a call to « gnome-terminal ». I would like the terminal to be launched on my graphical interface.
My grunt file is as follows
module.exports = function (grunt) {
// Project configuration
grunt.initConfig({
// Watching project content changes
// Both sections allow the watch of any file
// inside both directories, recursively (** means « at any
// place in the tree »
watch: {
options: {
event: [ 'added' ]
},
queued_scripts: {
files: [ "scripts_tank/**/*" ],
tasks: [ "exec:execute" ]
}
},
exec: {
execute : {
command: 'sh',
stdout: true,
stderr: true
}
}
});
// Loading plugins. They have to be loaded one at a time
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-exec');
grunt.registerTask('default', 'watch');
};
The output I get from the grunt watch command :
grunt watch
Running "watch" task
Waiting...OK
>> File "scripts_tank/ddksqj4E3fdjqsgdee4ERS.sh" added.
Running "exec:execute" (exec) task
No new terminal appears and the task never ends.
Is there anything in your plugin that could prevent a terminal to be launched from the process it created ?
Thanks in advance
I'm trying to use grunt-exec to execute a script on a remote machine that requires sudo access, and therefore prompts for a password.
I want it to prompt for the password, because I don't want to have to commit the password to source control.
From the command line the following is working correctly:
ssh -t examplehost.com "sudo ls"
However when I run the same command via grunt-exec I get the following:
$ grunt exec:remote_sudo
Running "exec:remote_sudo" (exec) task
>> Pseudo-terminal will not be allocated because stdin is not a terminal.
>> sudo: no tty present and no askpass program specified
>> Sorry, try again.
>> sudo: no tty present and no askpass program specified
>> Sorry, try again.
>> sudo: no tty present and no askpass program specified
>> Sorry, try again.
>> sudo: 3 incorrect password attempts
>> Exited with code: 1.
Warning: Task "exec:remote_sudo" failed. Use --force to continue.
Aborted due to warnings
The answer to this stackoverflow question with a similar error suggests adding an additional -t
switch to force the pseudo-terminal tty allocation.
Doing so gets the password prompt to show, but something isn't right, as it shows my password in the clear as I type it (the usual behaviour shows no output as you type), and it hangs forever:
$ grunt exec:remote_sudo
Running "exec:remote_sudo" (exec) task
[sudo] password for tom: not_my_password
# hangs forever here
Is this something grunt-exec should be capable of? Or is it considered beyond the scope of it's use?
Example Gruntfile.js
for reference:
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
exec: {
remote_sudo: 'ssh -t examplehost.com "sudo ls"',
}
});
};
grunt.registerHelper will be depreciated in grunt 0.4.
To see how helpers will be handled in the future (using standard npm require), check out the following links:
https://github.com/gruntjs/grunt-contrib-uglify/blob/master/tasks/uglify.js#L15 https://github.com/gruntjs/grunt-contrib-uglify/blob/master/tasks/lib/min.js
For instance when maxBuffer is exceeded (ref #64), the parent process (grunt) will kill the child.
In this case code
is null
, and the second argument of (signal
) is set. However the logic in the task does not check signal, and instead prints (the very confusing) message:
Exited with code: 0.
Warning: Task "exec:dockerNode" failed.� Use --force to continue.
Aborted due to warnings.
https://github.com/jharding/grunt-exec/blob/master/tasks/exec.js#L65
It uses child_process.spawn()
which preserves stdout/stderr colors.
If you'd rather use Node's API directly, here's how I'm currently doing it:
var child = child_process.spawn(app, [command], {cwd:cwd, stdio:"inherit"});
child.on("exit", function(code)
{
this.removeAllListeners();
callback();
});
#22 / #45 added support for the 'options' property, however this isn't referenced in the README:
https://github.com/jharding/grunt-exec/blob/master/README.md#properties
I try to execute a bash script but it turns error 'cause it interprets also the variables as pure commands and so it exits with error.
If it expects just pure commands also in bash script, really this plugin cannot be used to run more complex scripts with variable. Am I right or not?
See #66
What do the two red arrows mean?
remote: Running "exec:verify" (exec) task
remote: >> (these two arrows are red)
remote: HTTP/1.1 200 OK
remote: Server: nginx/1.4.3
remote: Date: Fri, 08 Nov 2013 10:05:21 GMT
remote: Content-Type: text/html
remote: Content-Length: 1161
remote: Last-Modified: Fri, 08 Nov 2013 10:04:37 GMT
remote: Connection: keep-alive
remote: ETag: "527cb735-489"
I'm doing a curl call to the index page after a deploy.
grunt exec:create_temp
Warning: Task "exec:create_temp" not found. Use --force to continue.
Aborted due to warnings.
Here's my definition:
exec: {
create_temp: {
cmd: 'mkdir -p <%= tmp_site_path %>'
}
},
I want grunt-exec to behave like make, with the option to default to a certain subtask (e.g., the "all" task), when the grunt user does not specify any particular grunt-exec subtask. This is useful when writing lots of grunt-exec shell commands, so that only a subset of them is run by default.
Looks like this may not be possible at the moment, the way multitasks work:
Would grunt-exec mind adding this option in a different way? I'm not sure grunt multitasks will ever add this feature.
Same as grunt-spawn and grunt-shell (couldn't post the issue there because the author is a bit of a dick).
Steps to reproduce:
git clone [email protected]:MeteorPackaging/summernote.git
cd summernote
git checkout meteor-integration
npm install
grunt meteor-test
This uses grunt-exec
(replace "shell" in the source lines) to execute meteor/runtests/sh
, which traps the INT signal.
Now press Ctrl+C.
Notice that grunt aborts instantly, without giving runtests.sh
a chance to trap the INT signal and do its cleanup.
It would be awesome if we could use directives with grunt-exec.
https://github.com/cowboy/grunt/blob/master/docs/helpers_directives.md
I am trying to execute the following where target is a sub-directory of where grunt.js is executing:
prepare: {
command: 'mkdir target/templates',
stdout: true
}
I get the following error:
"Command failed: The syntax of the command is incorrect."
If I try this, it works:
prepare: {
command: 'mkdir target2',
stdout: true
}
I'm not sure why I can't make a sub-directory. Of course, if I execute from command line, it works.
Hi,
I'm trying to pass arguments and it works OK but if I define a block of tasks like:
exec: {
commit: {
cmd: function(mensaje) {
return 'echo Mensaje: ' + mensaje;
}
}
},
[...]
grunt.registerTask('pre-commit', [
'clean',
'jshint',
'exec'
]);
The arguments won't work.
I'm running it like this:
grunt pre-commit:PARAMETRO
and it's showing undefined. Do you know how to do this?
Thanks in advance.
the child process exits with code 9 when I use the command zip to zip many files and directories, but it's ok to directly use the same command to zip these files and directories.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.