// 不优雅的判断管道判断
let d
process.stdin.on('data', chunk => {
  d = String(chunk)
})

setTimeout(() => {
  // console.log('d', d)
  if (d) {
    console.log('使用了管道')
  } else {
    console.log('没有使用管道')
    process.exit()
  }
}, 10);


// 不优雅的判断管道判断
const chunk = await new Promise((resolve, reject) => {
  process.stdin.on('data', chunk => {
    resolve(String(chunk))
  })
  setTimeout(() => resolve(undefined), 10)
})
if (chunk) {
  console.log('使用了管道')
} else {
  console.log('没有使用管道')
  process.exit()
}

相关文章:

  • 2021-07-07
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2021-04-24
  • 2022-12-23
  • 2021-12-07
猜你喜欢
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案