2

I am creating a Perl script that, among other things, sets into a ClearCase view, sources an environment, and runs synthesis tools, and finally post-processes output reports. It does that by piping to a shell process opened using IPC::open2.

If I set into the view manually before running the Perl script, it seems to work correctly (cleartool subcommands such as pwv work). However, when I run the $ct setview anassar_$proj in the script, it gives the following error message:

stty: standard input: Invalid argument

I am not aware of any constraints that prohibit running ct setview by piping it to a shell process. Any help?

my ( $readme, $writeme );
# Open the default shell and hook to its stdin and stdout.
my $pid = open2( $readme, $writeme, "$ENV{SHELL}" ) or
   croak "Cannot open IPC handles to $ENV{SHELL}\n";


runCmd("$ct pwv");
runCmd("$ct setview anassar_$proj");
runCmd("$ct pwv");
runCmd('source  /vobs/blah/blah/blah/env.csh');
runCmd('echo env_var1 = $env_var1');
runCmd('echo env_var2 = $env_var2');
runCmd('echo env_var3 = $env_var3');
runCmd('exit'); # Exit from ClearCase View
runCmd('exit'); # Exit from shell.


sub runCmd {
    my ( $cmd ) = @_;
    my $sentinel = '___SOME_STRING_THAT_CANNOT_OCCUR_IN_OUTPUT___';

    print $writeme "$cmd && echo $sentinel\n";

    while ( my $output = <$readme> ) {
        last if ( $output =~ /$sentinel/ );
        print $output;
    }
}
Ahmed Nassar
  • 4,683
  • 2
  • 19
  • 26
  • I have found [this answer](http://stackoverflow.com/questions/10252436/python-and-clearcase-setview) to a similar question. I tried to use `startview` and refer to the environment script using the path `/view/tagname/vobs/blah/blah/blah/env.csh`, but the environment script itself (which is not under my control) is directly using the `/vobs` hierarchy (i.e., needs a `setview`). The only solution I know of now is to use: `ct setview -exec "myscript" tagname` – Ahmed Nassar Aug 27 '13 at 00:01
  • I would recommed you one thing, although it probably will be impossible. Leave ClearCase as soon as you can. I was also solving a problem with Perl+cleartool. In my case it was how to pass 'CTRL+C' signal to cleartool through perl script which started cleartool update. It was impossible (on Windows). – René Kolařík Aug 27 '13 at 05:27
  • @RenéKolařík: Frankly, being a digital VLSI designer (rather than an IT infrastructure specialist), I encounter that hassle only occasionally. The heavy lifting remains with the IT department. I do only local customizations for my team. So from a user standpoint (a user who only previously used CVS and SVN), I feel ClearCase is well structured for controlling and tracking large projects (I am working on very large ones involving 1000's of designers and 10's of teams). Probably, I need to be exposed to other systems to realize what you're saying. – Ahmed Nassar Aug 27 '13 at 07:44

1 Answers1

2

As I mention in the answer you saw "Python and ClearCase setview", using setview in a script is generally not a good idea.

The only solution I know is two make 2 scripts:

  • one which ensure that setview is done, and /vobs/xxx refers to the right vob in the right view
  • one which will use /vobs.

Trying to do all in one step will mostly fail due to the sub-shell launched by setview.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Thanks, VonC. I guess the command `ct setview -exec "myscript.pl" tagname` should be equivalent to your two-script solution. Right? I just want to limit all functionality to one script and pass that one command in a crontab file? – Ahmed Nassar Aug 27 '13 at 07:30
  • @AhmedNassar I guess it is: let me know if that works, and I will add it to the answer. – VonC Aug 27 '13 at 07:31