Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #23156

Re: Why does this only work when I am running a shellscript

From Barb Knox <see@sig.below>
Newsgroups comp.lang.java.programmer
Subject Re: Why does this only work when I am running a shellscript
Date 2013-03-31 03:54 +1300
Organization I'm not unemployed; I'm a consultant
Message-ID <see-8C9CC4.03544931032013@news.eternal-september.org> (permalink)
References <8738vdmg0h.fsf@Servus.decebal.nl>

Show all headers | View raw


In article <8738vdmg0h.fsf@Servus.decebal.nl>,
 Cecil Westerhof <Cecil@decebal.nl> wrote:

> I have the following code:
>     private static void doCommand(final String cmd) throws IOException {
>         Process p;
>         Scanner sc;
> 
>         System.out.println("#" + cmd + "#");
>         p  = Runtime.getRuntime().exec(cmd);
>         sc = new Scanner(p.getInputStream());
>         while (sc.hasNext()) {
>             System.out.println(sc.nextLine());
>         }
>     }
> 
> When I call s shellscript like:
>     doCommand("createQuote.sh citation");
> 
> It works as I would expect. When I use something like:
>     /usr/bin/convert Š
> 
> It hangs. It is not the command, because if I execute the command I
> print in the shell directly, there is no problem.
> 
> So what is happening here?


I have not tested this, but I expect the Scanner is blocking waiting for 
input.  You might want to try  while (sc.hasNextLine()).

-- 
---------------------------
|  BBB                b    \     Barbara at LivingHistory stop co stop uk
|  B  B   aa     rrr  b     |
|  BBB   a  a   r     bbb   |    Quidquid latine dictum sit,
|  B  B  a  a   r     b  b  |    altum videtur.
|  BBB    aa a  r     bbb   |   
-----------------------------

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why does this only work when I am running a shellscript Cecil Westerhof <Cecil@decebal.nl> - 2013-03-30 09:46 +0100
  Re: Why does this only work when I am running a shellscript Barb Knox <see@sig.below> - 2013-03-31 03:54 +1300
    Re: Why does this only work when I am running a shellscript Steven Simpson <ss@domain.invalid> - 2013-03-30 16:07 +0000
  Re: Why does this only work when I am running a shellscript markspace <markspace@nospam.nospam> - 2013-03-30 08:23 -0700
    Re: Why does this only work when I am running a shellscript Arne Vajhøj <arne@vajhoej.dk> - 2013-03-30 11:34 -0400
  Re: Why does this only work when I am running a shellscript Roedy Green <see_website@mindprod.com.invalid> - 2013-03-30 08:35 -0700
  Re: Why does this only work when I am running a shellscript RVic <rvince99@hotmail.com> - 2013-03-30 08:41 -0700
    Re: Why does this only work when I am running a shellscript Joerg Meier <joergmmeier@arcor.de> - 2013-03-31 01:00 +0100
    Re: Why does this only work when I am running a shellscript Roedy Green <see_website@mindprod.com.invalid> - 2013-03-31 17:04 -0700
  Re: Why does this only work when I am running a shellscript Steven Simpson <ss@domain.invalid> - 2013-03-30 16:13 +0000

csiph-web