1

Hi I have the following method which when triggered should run a command in Git Bash.

function convert($tmpName, $fileName, $fileSize, $fileType){

}

The command will be something like this:

pyang -f yin -o H:\\YangModels\\yin\\ietf-inet-types.yin ietf-inet-types.yang

I was looking at shell commands here but don't know if this relates to Git Bash or not.

Just looking for a way to run commands in Git Bash when a PHP method runs, thanks.

The command has to be run through Git Bash it will not work through the normal command line or Windows shell.

Edit: Been looking into it more and found a command that could be similar to what I need. The user seems to be trying to run his command through cygwin, trying to specify mine to target git bash but haven't figured it out yet.

$result = shell_exec('C:/cygwin/bin/bash.exe /c --login -i git');
3
  • Possible duplicate of Running git pull from a php script Commented Feb 4, 2016 at 9:34
  • 1st try to run command on command prompt, then after follow same steps in your programing. you have exec(), system() and many more funcitons Commented Feb 4, 2016 at 9:35
  • hi tried the command on command prompt but it doesn't work, doesn't work in windows shell either, only seems to work in git bash Commented Feb 4, 2016 at 10:15

1 Answer 1

0

exec or shell_exec can run any command you would normally run via command line e.g.

shell_exec('cd /var/www && /path/to/git pull origin master');

I'm not sure exactly how your code is formed but it might be something like:

function convert($tmpName, $fileName, $fileSize, $fileType){
    $output = shell_exec('pyang -f '.$fileType.' -o '.$tmpName.' '.$fileName);
}
Sign up to request clarification or add additional context in comments.

3 Comments

hi thanks for the help, tried this out but the changes didn't occur. The command I'm trying to do only works in Git Bash not the normal command line, would this be why shell_exec is not working?
Can you provide the exact command that are using. The PATH variables might not be set, so try using the full path to the executable.
pyang -f yin -o H:\\YangModels\\yin\\ericsson-types-ipos.yin ericsson-types-ipos.yang is the full command. It works when I run it through Git Bash but I need to run it when that PHP method above triggers. I've tested it with the full path name too but no luck so far.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.