Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8758025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:26:38+00:00 2026-06-13T14:26:38+00:00

I am writing a small Scala script to generate PGP signatures for all the

  • 0

I am writing a small Scala script to generate PGP signatures for all the files in the current directory. This is what I wrote:

object PGPSign {
    def main(args: Array[String]) {
    signFilesInDirectory(new java.io.File("."))
  }

  def signFilesInDirectory(dir: java.io.File) {
    if(!dir.exists())
      throw new java.io.FileNotFoundException
    if(!dir.isDirectory())
      throw new RuntimeException("Expecting directory")
    println("Signing files in: " + dir.getAbsolutePath())
    for{ file <- dir.listFiles 
      if !file.isDirectory //ignoring directories
      val fileName = file.getName()
      if !fileName.startsWith(".") //ignoring hidden files
    } { 
      ("gpg -ab " + fileName).!!
    }
  }
}

In the console, the command gpg -ab FILE_NAME will request a password. When I execute my scala script I got this exception at the point of invoking the external command:

gpg: cannot open tty `/dev/tty': Device not configured
Exception in thread "main" java.lang.RuntimeException: Nonzero exit value: 2
at scala.sys.package$.error(package.scala:27)
at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.slurp(ProcessBuilderImpl.scala:131)
at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang$bang(ProcessBuilderImpl.scala:101)
at PGPSign$$anonfun$signFilesInDirectory$3.apply(PGPSign.scala:25)
at PGPSign$$anonfun$signFilesInDirectory$3.apply(PGPSign.scala:20)
at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:743)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:34)
at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:38)
at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:742)
at PGPSign$.signFilesInDirectory(PGPSign.scala:20)
at PGPSign$.main(PGPSign.scala:11)
at PGPSign.main(PGPSign.scala)

I have the idea this is related to the fact that the external command (gpg in this case) requests some input.
If this is what is creating the problem(?), what is the easiest general way to make any external command (requesting any amount of inputs) to work when executed from Scala ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:26:39+00:00Added an answer on June 13, 2026 at 2:26 pm

    gpg expects to be able to read from/write to a tty, which is not available unless gpg is started from an interactive shell. You should use the --no-tty option to disable this behavior. Also, you probably want batch mode, enabled with --batch.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a small Scala app that does the following: 1) Read XML/XHTML files
I intend on writing a small webapp using the Play framework with Scala and
Right now, I am trying to learn Scala . I've started small, writing some
I often find myself writing small (5-20 lines) files for things like input validation,
I'm writing small XMPP server using boost::asio and I want to unit-test my code.
I am writing small app, using Play Framework 2.0 which uses Ebean as ORM.
I have an application where I am reading and writing small blocks of data
I'm trying to practice my F# by writing small console scripts in F# in
Coming from a PHP background, I'm used to writing small functions that return a
I am writing a small program that sends and receive multicast packets.I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.