How to use the exec function from shelljs

Find comprehensive JavaScript shelljs.exec code examples handpicked from public code repositorys.

24
25
26
27
28
29
30
31
32
33

signale.info(`Did not find an existing code-intel-extensions bundles matching revision ${revision}.`)

signale.pending('Fetching code intel extensions bundles...')

const result = shelljs.exec(`curl -OLs https://github.com/sourcegraph/${bundlesRepoName}/archive/${revision}.zip`)

if (result.code !== 0) {
  console.error('Curl command failed with exit code:', result.code)
  console.error('Error message:', result.stderr)
fork icon936
star icon0
watch icon161

+ 11 other calls in file

131
132
133
134
135
136
137
138
139
140
    shell.exit(1)
  }
}

function exec(command, errorMsg) {
  const execResult = shell.exec(command)

  if (execResult.code !== 0) {
    if (errorMsg) {
      shell.echo(errorMsg)
fork icon669
star icon0
watch icon88

44
45
46
47
48
49
50
51
52
53
  shell.echo(
    `ℹ️ Pull Requests are welcome to add support for "msgcat" on Windows!`
  );
  shell.exit(0);
} else {
  msgcat = shell.exec('which msgcat 2>/dev/null', { silent: true }).stdout;
  if (!msgcat) {
    msgcat = shell.exec('find /usr -name "msgcat" -print -quit 2>/dev/null', {
      silent: true,
    }).stdout;
fork icon621
star icon0
watch icon161

+ 5 other calls in file

15
16
17
18
19
20
21
22
23
24
}

compileVyperContract(filename, compileABI, callback) {
  const self = this;
  const params = compileABI ?  '-f=json ' : '';
  shelljs.exec(`vyper ${params}${filename}`, {silent: true}, (code, stdout, stderr) => {
    if (stderr) {
      return callback(stderr);
    }
    if (code !== 0) {
fork icon533
star icon0
watch icon132

115
116
117
118
119
120
121
122
123
124
sh.cd(extensionDir);

extensionList.forEach(extension => {
  if (sh.test('-d', extension.path)) {
    sh.cd(extension.path);
    sh.exec('git checkout ' + extensionBranch);
    sh.exec('git pull');
  } else {
    sh.exec('git clone -b ' + extensionBranch + ' ' + extension.url);
    sh.cd(extension.path);
fork icon369
star icon0
watch icon92

+ 11 other calls in file

33
34
35
36
37
38
39
40
41
42
fs.copySync(path.join(__dirname, '../website'), dir);
console.log(chalk.green('Project folder was created successfully.'));

shell.cd(dir);
try {
  shell.exec('npm i');
} catch (err) {
  console.log(chalk.red('Dependencies install failed, please reinstall again!'));
  process.exit(1);
}
fork icon236
star icon0
watch icon46

53
54
55
56
57
58
59
60
61
  console.log('📍Failed to destroy aws key-pair remotely')
  process.exit(1)
}

console.log(`📍 Removing key-pair for ${keyName} locally ...`)
shell.exec(`rm ./${keyName}.pem`)
if (shell.error() !== null) {
  console.log(`📍Failed to delete ${keyName}.pem locally`)
}
fork icon37
star icon39
watch icon29

+ 44 other calls in file

8
9
10
11
12
13
14
15
16
17
const nextDevnetId = !fs.existsSync('./deployments')
  ? 1
  : findMaxDevnetId() + 1

shell.exec(`mkdir -p ./deployments/devnet-${nextDevnetId}`)
shell.exec(`cp ./.env ./deployments/devnet-${nextDevnetId}/.env`)
shell.exec(
  `cp ./secret.tfvars ./deployments/devnet-${nextDevnetId}/secret.tfvars`
)
shell.exec(`cp ./main.tf ./deployments/devnet-${nextDevnetId}/main.tf`)
fork icon37
star icon39
watch icon0

+ 6 other calls in file

200
201
202
203
204
205
206
207
208
209

return new Promise(async (resolve, reject) => {
    try {
        shell.cd(STATIC_URL)
        const targz = `tar zcf bklesscode-proj-${projectId}.tar.gz -C ./${sourceDir} .`
        shell.exec(targz)
        shell.cd(projectPath)

        const uploadKey = `project/${projectId}/${version}/${releaseId}/`
        const url = await fileService.uploadFile(`${targetPath}.tar.gz`, uploadKey)
fork icon32
star icon31
watch icon9

59
60
61
62
63
64
65
66
67
68

const feesFileId = 111;
const queryFees = new HederaSDK.FileContentsQuery()
    .setFileId(`0.0.${feesFileId}`);
const fees = (await queryFees.execute(client)).toString('hex');
await shell.exec(
    `docker exec mirror-node-db psql mirror_node -U mirror_node -c "INSERT INTO public.file_data(file_data, consensus_timestamp, entity_id, transaction_type) VALUES (decode('${fees}', 'hex'), ${timestamp + '000000'}, ${feesFileId}, 17);" >> ${NodeController.getNullOutput()}`
);

const exchangeRatesFileId = 112;
fork icon25
star icon26
watch icon0

+ 3 other calls in file

331
332
333
334
335
336
337
338
339
340
341
 
/**
 * 检测当前工程是否是git工程
 */
 function isGitRepo(){
    return shelljs.exec("git status", {silent: true}).code === 0;
}


/**
 * 简单进行对象合并
fork icon3
star icon24
watch icon3

+ 167 other calls in file

21
22
23
24
25
26
27
28
29
30
31
gulp.task("aspmvc-build", aspmvcBuild);


gulp.task('deploy', function(done) {
    // remove clone folder
    shelljs.rm('-rf', './ej2aspmvc');
    var commitMessage = shelljs.exec('git log -1 --pretty=%B').stdout.trim();
    console.log('COMMIT MESSAGE: ' + commitMessage);
    // create clone directory
    fs.mkdirSync('./ej2aspmvc');
    // navigate to clone location
fork icon27
star icon9
watch icon13

+ 199 other calls in file

722
723
724
725
726
727
728
729
730
731
pipe([
  tap(() => {
    logger.debug(`shellRun: ${fullCommand}`);
  }),
  () =>
    shell.exec(fullCommand, {
      silent: true,
    }),
  switchCase([
    eq(get("code"), 0),
fork icon12
star icon78
watch icon6

+ 17 other calls in file

331
332
333
334
335
336
337
338
339
340
  return filenames
} else {
  const command = `git diff --name-only --diff-filter=AMR origin/${branch}`
  debugGit('command: %s', command)

  const result = shell.exec(command, { silent: true })
  if (result.code !== 0) {
    debugGit('git diff failed with code %d', result.code)
    return []
  }
fork icon6
star icon26
watch icon2

+ 44 other calls in file

6
7
8
9
10
11
12
13
14
15
16
17
18
}


function shellExecute (command) {
  const { exec } = require('shelljs')


  return exec(command, { silent: true }).stdout
}


function gitLogCommand (path) {
  return `git log --pretty=format:'%H' -n 1 ${path}`
fork icon3
star icon4
watch icon1

+ 22 other calls in file

8
9
10
11
12
13
14
15
16
17
18
19
  })


  it('returns the last file SHA', () => {
    const pathToFile = `${process.cwd()}/test/fixtures/test.txt`
    const gitLogCommand = `git log --pretty=format:'%H' -n 1 ${pathToFile}`
    const expectedSha = exec(gitLogCommand, { silent: true }).stdout


    expect(sha(pathToFile)).toEqual(expectedSha)
  })
})
fork icon3
star icon4
watch icon1

+ 22 other calls in file

9
10
11
12
13
14
15
16
17
18
{
    console.error('Script must be run with the commit SHA for the latest merged PR to pixijs/pixijs dev!');
    process.exit(1);
}

shell.exec('npm view pixi.js --json > scripts/pixiVersions.json');

const codeSandboxBaseUrl = `https://pkg.csb.dev/pixijs/pixijs/commit/${devCommitSha.substring(0, 8)}`;

// eslint-disable-next-line global-require
fork icon1
star icon6
watch icon4

+ 5 other calls in file

99
100
101
102
103
104
105
106
107
  // start the Metro server in a separate window
  launchPackagerInSeparateWindow();

  // launch the app on iOS simulator
  pushd('packages/rn-tester');
  exec('npx react-native run-ios --scheme RNTester --simulator "iPhone 14"');
  popd();
} else {
  // we do the android path here
fork icon2
star icon0
watch icon0

+ 33 other calls in file

9
10
11
12
13
14
15
16
17
18
19
 * Executes a Command
 * @param {String} command
 * @returns {Void}
 */
function exec(command) {
    Shell.exec(command);
}


/**
 * Executes a Silent Command
fork icon0
star icon3
watch icon0

+ 3 other calls in file

130
131
132
133
134
135
136
137
138
139
140
    exit(1);
  }
}


function checkIfTagExists(version) {
  const {code, stdout} = exec('git tag -l', {silent: true});
  if (code !== 0) {
    throw new Error('Failed to retrieve the list of tags');
  }
  const tags = new Set(stdout.split('\n'));
fork icon2
star icon0
watch icon0

+ 9 other calls in file